Getting a list of xml element from Descendants

3g23r973rg9

New Member
This is my Xml file:\[code\]<?xml version="1.0" encoding="utf-8" ?><dati> <product id="456"> <item>a</item> <item>b</item> <item>c</item> </product> <product id="789"> <item>a</item> <item>b</item> </product> <product id="533"> <item>a</item> </product></dati>\[/code\]Code below returns only first item.InnerText element\[code\]List<string> lst = new List<string>();XDocument Doc = XDocument.Load("test.xml");var q = from c in Doc.Descendants("product") where c.Attribute("id").Value =http://stackoverflow.com/questions/10552454/="789" select c.Element("item");foreach (string name in q) lst.Add(name);listBox1.DataSource = lst;\[/code\]how can I have a collection of all items for selected product?
 
Back
Top