Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath for missing node

Tags:

xml

xpath

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?

like image 415
dcg Avatar asked Sep 25 '12 10:09

dcg


People also ask

What is current node in XPath?

Current node is the node that the XPath processor is looking at when it begins evaluation of a query. In other words, the current node is the first context node that the XPath processor uses when it starts to execute the query. During evaluation of a query, the current node does not change.

How do you check if an element exists in the XML using XPath?

Use the fn:nilled XPath function to test whether the value of an input element has the xsi:nil attribute set. Use the fn:exists XPath function to test whether the value of an input element is present. Note: An XML element that has the xsi:nil attribute set is considered to be present.

What is syntax for XPath?

Syntax of XPath Below is the syntax for Xpath: Xpath =//tagname[@Attribute='value'] Wherein: //: Used to select the current node. tagname: Name of the tag of a particular node.

What is XPath expression in XML?

XPath uses path expressions to select nodes or node-sets in an XML document. These path expressions look very much like the expressions you see when you work with a traditional computer file system. XPath expressions can be used in JavaScript, Java, XML Schema, PHP, Python, C and C++, and lots of other languages.


1 Answers

Try the following xpath:

/root/node[not(tag2)]
like image 146
dogbane Avatar answered Sep 21 '22 10:09

dogbane