【发布时间】:2010-04-26 14:41:11
【问题描述】:
给定以下 XML 结构:
<courses>
<course>
<title>foo</title>
<description>bar</description>
</course>
...
</courses>
如何创建一个字典数组,使每个字典都包含课程中的所有元素/值对?
我现在所拥有的会生成一个数组,其元素包含课程中每个元素/值对的单个键/值字典:
XElement x = XElement.Parse("...xml string...");
var foo = (from n in x.Elements() select n)
.Elements().ToDictionary(y => y.Name, y => y.Value);
生产:
[0] => {[course, foo]}
[1] => {[description, bar]}
我想要的是这个:
[0] => {[course, foo], [description, bar]}
【问题讨论】:
标签: c# xml linq arrays dictionary