Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

Reading XML documents using LINQ

, 18 Jan 2011
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);}

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

14 Jan 2011
Andrew Rissing
Not really that big of a change, but I'd go with an XPath solution. It locates all of the "magic strings" into one spot.var nodes = from element in XElement.Load("Books.xml").XPathSelectElements("/Books/Book/Subject") select new { Value =...
15 Jan 2011
Anupama Roy
2 alternatives  
Reading XML documents using LINQ

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Richard Deeming
Software Developer Nevalee Business Solutions
United Kingdom United Kingdom
No Biography provided
Follow on   Twitter   Google+

| | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 18 Jan 2011
Article Copyright 2011 by Richard Deeming
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid