Click here to Skip to main content
12,558,802 members (29,001 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


21 bookmarked

Reading XML documents using LINQ

, 15 Jan 2011 CPOL
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 
Reason for my vote of 5
Just what I needed.
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    Praise Praise    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
Web01 | 2.8.161026.1 | Last Updated 16 Jan 2011
Article Copyright 2011 by Anupama Roy
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid