65.9K
CodeProject is changing. Read more.
Home

Reading XML documents using LINQ

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.20/5 (5 votes)

Jan 18, 2011

CPOL
viewsIcon

8530

Another option would be to use the Elements extension method[^]:var root = XElement.Load("Books.xml"); var books = from node in root.Elements("Book").Elements("Subject") select node.Value.Trim(); foreach (string subject in books){ listBox1.Items.Add(subject);}

Another option would be to use the Elements extension method[^]:
var root = XElement.Load("Books.xml");
 
var books = from node in root.Elements("Book").Elements("Subject")
            select node.Value.Trim();
 
foreach (string subject in books)
{
    listBox1.Items.Add(subject);
}