小编dha*_*ton的帖子

Linq to XML问题:为什么我的查询不起作用

在我的问题上,我在XElement中有以下XML.完整的XML中可以有许多这些"标识符"节点,我的导航工作到此为止.

    <Identifiers>
      <identifier>
        <Type>MR</Type>
        <Value>123321</Value>
        <Authority></Authority>
      </identifier>
      <identifier>
        <Type>AN</Type>
        <Value>123321-01</Value>
        <Authority></Authority>
      </identifier>
      <identifier>
        <Type>PN</Type>
        <Value>123321</Value>
        <Authority></Authority>
      </identifier>
    </Identifiers>
Run Code Online (Sandbox Code Playgroud)

这是Linq-To-XML:

    id = xd.Root.Element("Patient");
    id = id.Element("Identifiers"); //At this point "id" contains the above XML.
    id = id.Elements("Identifier").FirstOrDefault(x => x.Element("Type").Value == "AN");
Run Code Online (Sandbox Code Playgroud)

是它崩溃的最后一个语句,并返回null.

我在这里错过了什么?

c# xml linq-to-xml

1
推荐指数
1
解决办法
99
查看次数

标签 统计

c# ×1

linq-to-xml ×1

xml ×1