I have a xml like this.
<?xml version="1.0" encoding="utf-8" ?>
<Category ID="1" AICategoryName="Schedule K: Income/Loss" Taxonomy="K">
<Level1 ID="11965" Name="Guaranteed payments" Taxonomy="4">
<Level2 ID="27058" Name="Gtd Pmts(trade/bus) to Sch. M-1" Taxonomy="1">
</Level2>
<Level2 ID="27059" Name="Gtd Pmts not to Sch. M-1" Taxonomy="2">
</Level2>
</Level1>
<Level1 ID="119652" Name="2Guaranteed payments" Taxonomy="4">
<Level2 ID="227058" Name="2Gtd Pmts(trade/bus) to Sch. M-1" Taxonomy="1">
</Level2>
<Level2 ID="227059" Name="2Gtd Pmts not to Sch. M-1" Taxonomy="2">
</Level2>
</Level1>
</Category>
I want to get the child nodes under a parent node by providing the parent node attribite ID.
for example if I provide Level1 and 11965, I should get all the level 2 nodes and their Name and IDs.
I have tried this code.
XDocument xd = XDocument.Load(xmlPath);
var xl = from xml2 in xd.Descendants("Level1")
where xml2.Parent.Attribute("ID").Value == parentNode.ID
select xml2;
But the code yeilds no results. also once I get the xl, how can I iterate through it to get child node names and IDs?
you can also change the code above if the tag name requested is always “Level1” and the xml struvvture is fixed, to this.