Finding a string inside an XmlDocument
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#?
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.
精彩评论