0
如果我有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
};
但無濟於事。我會怎麼做呢?
謝謝。
它不應該是.Descendants(「選擇」) – 2008-11-27 20:45:04