Given:
a xmlnode that you got from calling the XmlDocument.GetSingleNode method,
where you know that the node is an element,
if you want to find the simple path to that element, is there something more straightforward than climbing the tree til you get to the root node and buildling the path as you go? Not that that’s hard, I just would have expected there’s an existing method/property to get back a string representing the path.
I can see that “the simple path” might not be an easy-to-nail-down term, what I mean is the slash-separated list of elements beginning with “/”, using the child axis, that leads to the node I have in hand.
Thanks
I am not aware of a built-in method to do that, and I don’t really see the benefit either.
Because identifying a node by its index is not reliable if the document can change, and how would you identify it in a generic way otherwise? If you want to keep a runtime pointer to a node on a document which does not change, you don’t need to traverse the tree to find it since you can just keep a XPathNavigator to it or a reference to XmlElement or whatever in order to get back to the node.