Is there an XPath equivilent for Linq to XML?

杀马特。学长 韩版系。学妹 提交于 2020-01-11 20:01:14

问题


I have been using Linq to XML for a few hours and while it seems lovely and powerful when it comes to loops and complex selections, it doesn't seem so good for situations where I just want to select a single node value which XPath seems to be good at.

I may be missing something obvious here but is there a way to use XPath and Linq to XML together without having to parse the document twice?


回答1:


You can still use XPath, with the XPathEvaluate, XPathSelectElement and XPathSelectElements extension methods. You can also call CreateNavigator to create an XPathNavigator.



来源:https://stackoverflow.com/questions/1294386/is-there-an-xpath-equivilent-for-linq-to-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!