Linq to XML是否有XPath替代品? [英] Is there an XPath equivilent for Linq to XML?

查看:77
本文介绍了Linq to XML是否有XPath替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Linq to XML了几个小时,虽然在循环和复杂选择方面看起来很可爱并且功能强大,但是对于我只想选择一个单节点值的情况似乎不太好XPath似乎很擅长.

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.

我在这里可能会遗漏一些明显的东西,但是有没有一种方法可以将XPath和Linq一起用于XML,而不必两次分析文档?

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?

推荐答案

您仍然可以将XPath与 XPathSelectElement CreateNavigator 创建XPathNavigator.

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

这篇关于Linq to XML是否有XPath替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆