tags:

views:

64

answers:

1

Hi, I need to find an inner text of an element inside an XmlDocument and return it's Xpath. for example, searching for "ThisText" inside :

<xml>
<xml2>ThisText</xml2>
</xml>

should return the Xpath of xml2

what's the most efficient way of doing this in c#?

+6  A: 

What do you think the "xpath" of an element is? An xpath is a querying language in order to find a node/nodes, not to describe where a node is.

You can use an xpath to find the element in question. e.g.

xmlDocument.SelectNodes("//*[contains(text(), 'ThisText')]");

Then you can loop through the returned nodes and look at their name / parent, etc.

Robin Day