c# - Linq to XML 问题 : Why is my query not working

标签 c# xml 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>

这是 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");

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

我在这里错过了什么?

最佳答案

由于 XML 区分大小写,请尝试用“identifier”替换上一条语句中的“Identifier”。

关于c# - Linq to XML 问题 : Why is my query not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9041457/

相关文章:

c# - XmlDocument.SelectSingleNode 使用哪个版本的 XPath?

xml - Android XML 解析省略 "&amp;"

c# - 使用 XmlWriter 以迭代方式构建 XML 文件

c# - LINQ to Array in Silverlight 2

c# - 如何发送 Microsoft Graph 上传 session 的最终字节?

java - 删除 XML 结构 Java DOM 中的节点

c# - 通过 C# 将 LINQ to XML

c# - XPathSelectElements 总是在带有命名空间的 XML 中返回空?

c# - 从 Linq-to-Entities 中选择 Linq-to-XML?

c# - 查找 2 个巨大区域(文本)文件之间的变化