对 XLinq 帮助不大
我有这个 XML:
<Test>
<element>toto</element>
<element>tata</element>
</Test>
如何获取节点“元素”?。我在网上看到我可以通过以下方式获取它们:
var elements = from element in xmlDoc.Descendants("element")
select element;
但是“元素”是空的!
编辑 1: 我正在使用以下确切的 XML 加载 XDocument:
<Test xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">
<element>toto</element>
<element>tata</element>
</Test>
I have this XML:
<Test>
<element>toto</element>
<element>tata</element>
</Test>
How I can get the nodes "element"?. I see on the web I can get them with:
var elements = from element in xmlDoc.Descendants("element")
select element;
But "elements" is empty!
EDIT 1: I'm loading the XDocument with this exact XML:
<Test xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">
<element>toto</element>
<element>tata</element>
</Test>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这就是您的问题,您的名称必须使用适当的 XML 命名空间进行限定。
Ok well there's your problem, your names have to be qualified with the appropriate XML namespace.
这可能是您创建
XDocument
对象的方式有问题。以下代码对我来说效果很好:It is probably a problem with how you are creating your
XDocument
object. The following code works fine for me: