问候!
我有一些这样的 XML:
<Root>
<AlphaSection>
.
.
.
</AlphaSection>
<BetaSection>
<Choices>
<SetA>
<Choice id="choice1">
<Title>Choice 1 Title</Title>
<Body>Choice 1 Body</Body>
</Choice>
<Choice id="choice2">
<Title>Choice 2 Title</Title>
<Body>Choice 2 Body</Body>
</Choice>
</SetA>
<SetB>
<Choice id="choice3">
<Title>Choice 3 Title</Title>
<Body>Choice 3 Body</Body>
</Choice>
<Choice id="choice4">
<Title>Choice 4 Title</Title>
<Body>Choice 4 Body</Body>
</Choice>
</SetB>
</Choices>
</BetaSection>
<GammaSection>
.
.
.
</GammaSection>
</Root>
我目前正在执行以下操作来检索每个选项的 ID:
var choiceList = myXDoc.Root
.Element("BetaSection")
.Descendants("Choice")
.Select(element => new
{
ID = element.Attribute("id").Value,
// Title = ?
// Body = ?
});
我还想获取每个选项的 Title 和 Body 子节点中的值。我该怎么办?谢谢。