【发布时间】:2012-02-06 23:23:55
【问题描述】:
我有一个以下格式的 xml 文档。
<?xml version="1.0" encoding="UTF-8" ?>
<Rows>
<Row>
<Field Name='PhysicalLocation'>11;#West</Field>
<Field Name='ID'>3327</Field>
</Row>
</Rows>
并且正在尝试使用它进行 linq 选择。
我已经尝试了以下方法。
XDocument xmlDoc = XDocument.Load("C:\\manifest.xml");
var query = from item in xmlDoc.Descendants("Rows").Elements()
select new { ID = item.Attribute("ID").Value, Value = item.Attribute("PhysicalLocation").Value };
还有
XDocument xmlDoc = XDocument.Load("C:\\manifest.xml");
var query = from item in xmlDoc.Descendants("Rows").Elements()
select new { ID = item.Element("ID"), Value = item.Element("PhysicalLocation") };
在这两种情况下,我似乎都做不到。它正在生成预期数量的行,但未填充值。
谁能指出我正确的方向?我错过了什么?
【问题讨论】:
标签: .net xml linq linq-to-xml