Reading XML documents using LINQ






4.20/5 (5 votes)
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);
}