开发者

Finding a string inside an XmlDocument

开发者 https://www.devze.com 2022-12-29 06:44 出处:网络
I need to find an inner text of an element inside an XmlDocument and return it\'s Xpath. for example, searching for \"ThisText\" inside :

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号