我知道这个问题似乎很混乱,因为它对我来说很混乱。我认为我最好以身作则。我有一个部分xml文件,如下所示。我需要获取VALUE
节点的DIALVALUE
子节点的值,但是要获取正确的值,我需要通过DIALVALUE
id属性找到正确的DIAL
节点。 xml文件中DIALVALUE
节点被列出71次,所需的值不正确。如何做到这一点?
<?xml version="1.0" encoding="utf-16"?>
<OrderXml>
<DialValues>
<DialValue>
<Dial id="11144" externalId="">
<PlanName>pg1_CreditUnionName</PlanName>
<DisplayName>Credit Union Name:</DisplayName>
</Dial>
<Value>Alexis Nab Credit Union</Value>
</DialValue>
<DialValue>
<Dial id="11145" externalId="">
<PlanName>pg1_CharterNumber</PlanName>
<DisplayName>Charter Number:</DisplayName>
</Dial>
<Value>9999</Value>
</DialValue>
<DialValue>
<Dial id="11146" externalId="">
<PlanName>pg1_ContactNameFirst</PlanName>
<DisplayName>Solution Main Contact First Name:</DisplayName>
</Dial>
<Value>Alexis</Value>
</DialValue>
<DialValue>
</DialValues>
<OrderXml>
var value = XDocument.Parse(xml)
.Descendants("Dial")
.Single(el => el.Attribute("id").Value == "11145")
.Parent.Descendants("Value").Single().Value;