A basic LINQ to XML Example

We are going to parse this xml file. A snippet of the file is here

xml file snippet

The code to parse the above xml file in LINQ to XML is below

            //Load the productstable.xml in memory
            XElement doc = XElement.Load(@"....books.xml");

            //Query xml doc
            var books = from book in doc.Descendants("book")
                           select book.Element("author");

            //Display details
            foreach (var book in books)
This entry was posted in Software Development. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s