How to select and iterate through a XML xElement node from attribute values?

chav

New Member
I have a xml like this.\[code\]<?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>\[/code\]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.\[code\]XDocument xd = XDocument.Load(xmlPath); var xl = from xml2 in xd.Descendants("Level1") where xml2.Parent.Attribute("ID").Value =http://stackoverflow.com/questions/10394509/= parentNode.ID select xml2;\[/code\]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?
 
Back
Top