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?
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.
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.
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.
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.
Try the following xpath:
/root/node[not(tag2)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With