问候!
如果我有这样的 XML:
<Root>
<AlphaSection>
.
.
.
</AlphaSection>
<BetaSection>
<Choices>
<SetA>
<Choice id="choice1">Choice One</Choice>
<Choice id="choice2">Choice Two</Choice>
</SetA>
<SetB>
<Choice id="choice3">Choice Three</Choice>
<Choice id="choice4">Choice Four</Choice>
</SetB>
</Choices>
</BetaSection>
<GammaSection>
.
.
.
</GammaSection>
</Root>
我想获得“BetaSection”中的所有选择项,无论它们属于哪个“集合”。我尝试了以下方法:
var choiceList = from choices in myXDoc.Root.Element("BetaSection").Elements("Choices")
where (choices.Name == "Choice")
select new
{
Name = choices.Attribute("id").Value,
Data = choice.Value
};
但无济于事。我该怎么办?
谢谢。