【发布时间】:2016-12-19 19:48:55
【问题描述】:
我有一个看起来像这样的 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<Content>
<Field Title="XYZ">
<Description>Numeric</Description>
<Comment>12345</Comment>
</Field>
<Field Title="ABC">
<Description>Alphabetic</Description>
<Comment>QWERTY</Comment>
</Field>
<Field Title="XYZ">
<Description>Alphabetic</Description>
<Comment>QWERTY</Comment>
</Field>
</Content>
我想提取 <Description> 和 <Comment> 的节点值
属于属性Title 和Value='XYZ'
我使用 Linq to Xml 尝试了类似的操作,但没有得到预期的结果
string Xmlpath = @"d:\Test.xml";
XDocument mappings = XDocument.Load(Xmlpath);
var Data = from elm in mappings.Descendants("Field")
where (string)elm.Attribute("Title") == "XYZ"
select elm;
有人可以帮我吗?
【问题讨论】:
标签: asp.net xml linq c#-4.0 linq-to-xml