【发布时间】:2010-05-14 00:27:12
【问题描述】:
我有以下 XML:
<FootNotes>
<Line id="10306" reference="*"></Line>
<Line id="10308" reference="**"></Line>
<Line id="10309" reference="***"></Line>
<Line id="10310" reference="****"></Line>
<Line id="10311" reference="+"></Line>
</FootNotes>
我有以下代码,我将在其中获取 Dictionary<int, string>() 对象
myObject.FootNotes
这样每一行都是一个键/值对
var doc = XElement.Parse(xmlString);
var myObject = new
{
FootNotes = (from fn in doc
.Elements("FootNotes")
.Elements("Line")
.ToDictionary
(
column => (int) column.Attribute("id"),
column => (string) column.Attribute("reference")
)
)
};
我不确定如何将它从 XML 中获取到对象中。任何人都可以提出解决方案吗?
【问题讨论】:
标签: c# dictionary linq-to-xml