Click here to Skip to main content
11,790,387 members (65,256 online)
Click here to Skip to main content

Tagged as

Reading XML documents using LINQ

, 15 Jan 2011 CPOL 29.9K 21
Rate this:
Please Sign up or sign in to vote.
Reading XML documents using LINQ
LINQ simplifies working with XML data & you need not use Xpath or XQuery for reading XML. This tip is about querying XML using LINQ.
<?xml version="1.0" encoding="utf-8" ?>
      Social Science
     General Science
This queries the XML & populates the listbox with values of Subject.

var books = from nodes in System.Xml.Linq.XElement.Load("Books.xml").Elements("Book") select nodes;
            if (books != null)
                foreach (var b in books)


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


About the Author

Anupama Roy
Software Developer (Senior) Dell
India India
I am a .Net developer working on C#,,WCF,WF etc.I would like to utilize this space to share whatever I have come across so far working in .Net so that you can also learn & explore.

I hope you find these posts useful.I’d love to hear from you,so please post in your comments/feedback.

Visit my blog for more technical articles:

You may also be interested in...

Comments and Discussions

QuestionMinh Pin
hoangminh1235-Aug-13 22:31
memberhoangminh1235-Aug-13 22:31 
GeneralMy vote of 4 Pin
Member 1011024015-Jun-13 13:00
memberMember 1011024015-Jun-13 13:00 
GeneralReason for my vote of 5 just the biscuit thanks for the tip! Pin
Erik Rude22-Feb-12 22:51
memberErik Rude22-Feb-12 22:51 
GeneralReason for my vote of 5 Just what I needed. Pin
[Schnell]Konig18-Dec-11 12:26
member[Schnell]Konig18-Dec-11 12:26 
GeneralIn most cases, a query expression of "from x in source selec... Pin
Richard Deeming18-Jan-11 9:19
memberRichard Deeming18-Jan-11 9:19 
Question?......really? Pin
trooper081417-Jan-11 3:34
membertrooper081417-Jan-11 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1509028.1 | Last Updated 16 Jan 2011
Article Copyright 2011 by Anupama Roy
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid