If I call SelectNodes on an XmlElement, and pass XPath query such as this:
XmlNodeList nodes = xmlElement.SelectNodes("//OtherNode");
The nodes list will be for all the OtherNode elements in the document not just the ones from xmlElement.
I seem to recall that this is by design, and for a good reason, but I can't remember what that good reason was, nor how to get around it.
Just add a dot
to the beginning of the xpath
. The dot
selects the current node:
XmlNodeList nodes = xmlElement.SelectNodes(".//OtherNode");
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