我有像这样的XML:
<RES>
<MUL>
<SIN>
<KEY name="a">
<VALUE>a1</VALUE>
</KEY>
<KEY name="b">
<VALUE>b1</VALUE>
</KEY>
<KEY name="c">
<VALUE>c1</VALUE>
</KEY>
<KEY name="need">
<MUL>
<SIN>
<KEY name="needID">
<VALUE>ID</VALUE>
</KEY>
<KEY name="needOther">
<VALUE>other</VALUE>
</KEY>
<KEY name="needOther2">
<VALUE>other2</VALUE>
</KEY>
</SIN>
</MUL>
</KEY>
</SIN>
</MUL>
</RES>
我的问题是如何从名称为的节点获取值“id” needID
?
我试过了
XmlDocument xx = new XmlDocument();
xx.Load(MYDOC);
XmlNodeList node = xx.SelectNodes("/RES/MUL/SIN/KEY[@name='need']");
但在那之后我不能选择需要ID
XDocument doc = new XDocument(node);
var cource = from x in doc.Descendants("KEY")
select new { ID = doc.Element("VALUE").Value };
请帮我!
谢谢!:)