Click here to Skip to main content
11,577,643 members (23,009 online)
Click here to Skip to main content

Tagged as

Reading XML documents using LINQ

, 14 Jan 2011 CPOL 5.2K 1
Rate this:
Please Sign up or sign in to vote.
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 =...
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 = element.Value.Trim()
            };
 
foreach (var n in nodes)
{
    listBox1.Items.Add(n);
}

License

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

Share

About the Author

Andrew Rissing
Software Developer (Senior)
United States United States
Since I've begun my profession as a software developer, I've learned one important fact - change is inevitable. Requirements change, code changes, and life changes.

So..If you're not moving forward, you're moving backwards.

You may also be interested in...

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150603.1 | Last Updated 14 Jan 2011
Article Copyright 2011 by Andrew Rissing
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid