【发布时间】:2014-05-25 11:01:19
【问题描述】:
我在从我的 XML 文件中获取所有标签时遇到问题。在我的 XML 文件中,我有一个选项标签,其中包含描述。
<selection id="1">
<desc>You see a cat stuck up in a tree, do you</desc>
<option>
<desc goto_id="2">Help the cat</desc>
<desc goto_id="3">Leave the cat stuck in the tree</desc>
</option>
</selection>
我已经设法从选择中获取描述和 ID,但是当我尝试在对象上创建一个数组时,它只会在循环遍历它时获得第一个。
var selectionQueryNew = from selection in xml.Root.Descendants("selection")
select new {
Desc = selection.Element("desc").Value,
Id = selection.Attribute("id").Value,
Options = selection.Elements("option")
.Select(option => new {
Desc = option.Element("desc").Value
}).ToArray()
};
我认为 .Select 区域有问题,知道为什么它只会从 XML 文件中选择第一个描述吗?
【问题讨论】: