I have XML like:
<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>
My question is how to get value ‘id’ from the node with the name of needID ?
I tried with
XmlDocument xx = new XmlDocument();
xx.Load(MYDOC);
XmlNodeList node = xx.SelectNodes("/RES/MUL/SIN/KEY[@name='need']");
but after that I can’t pick needID with
XDocument doc = new XDocument(node);
var cource = from x in doc.Descendants("KEY")
select new { ID = doc.Element("VALUE").Value };
Please, help me!
Thanks! 🙂
You need something like this:
or you could even combine that into a single XPath operation, assuming you know that you have at most one single matching node in your XML document: