1
我想创建一个通用的方法,它将读取一个xml并返回节点名称和属性值作为字典项目。如何从xml创建字典项目?
我一直在玩弄语法,但似乎无法完全正确。 我在这里错过了什么?
目前我有:
XElement doc = XElement.Load(dataStream);
var item = from el in doc.Descendants()
where el.Attribute(attributeName) != null
select new
{
Name = el.Name.LocalName,
Value = el.Attribute(attributeName).Value
}.ToDictionary(o => o.Name, o => o.Value);
我正要张贴我的答案。我没有意识到我忘了包装查询。 – PrivateJoker