<World>
<Animals>
<Tab>
<Dogs id ="1">
<Dog1></Dog1>
<Dog2></Dog2>
<Dog3></Dog3>
</Dogs>
<Dogs id ="2"></Dogs>
<Dogs id ="3"></Dogs>
</Tab>
</Animals>
</World>
如何获取标签下的所有元素,其中id == 1?C#Linq to XML查询
我的Linq查询。 (不起作用)为什么?
XDocument xml= XDocument.Load(xml.xml);
var elements = from e in xml.Descendants("Animals").Descendants("Tab").Elements("Dogs")
where e.Attribute("id").toString().Equals("1")
select c;
请问您能检查一下吗?
谢谢!
谢谢!问题出在n.Attiribute(“id”)。VALUE。 (我忘了加.value) – 2012-02-20 15:27:46
:)不客气! – sll 2012-02-20 15:29:05