How "XDocument.Descendants" work? [modified]
LINQ
1
Posts
1
Posters
1
Views
1
Watching
-
Hello, I have read two samples from MSDN XDocument..::.Descendants Method[^].. but I still don't understand about that. For example: The following code is working fine. string xmlString = "" + "" + "1BigMac13510" + "3Coka25" + "4ApplePie18" + ""; XDocument xmlSource = XDocument.Parse(xmlString); var yourItems = from g in xmlSource.Descendants ("eachitem") select new { fid = g.Element ("fid").Value, fname = g.Element ("fname").Value }; foreach ( var itm in yourItems ) { Console.WriteLine ("FID: {0}, Name: {1}", itm.fid, itm.fname); } So, we are able to query one level nested XML. (eg. records\eachitem).. What about more than one nested level? For example: string xmlString = "" + "" + "" + "1BigMac13510" + "3Coka25" + "4ApplePie18