在我的问题点,我在 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/