dcg
dcg

Reputation: 1271

xpath for missing node

I have the following xml:

<root>
  <node>
     <tag1/>
     <tag2/>
     <tag3/>
  </node>
  <node>
     <tag1/>
     <tag2/>
     <tag3/>
  </node>
  <node>
     <tag1/>
     <tag3/>
  </node>
</root>

As you can see, in the 3rd node I have a missing tag2. Is there any xpath I can apply to a c# XmlDocument (via SelectNodes) that can return me the node that does not have the tag2 node?

Upvotes: 10

Views: 6595

Answers (1)

dogbane
dogbane

Reputation: 274670

Try the following xpath:

/root/node[not(tag2)]

Upvotes: 23

Related Questions