LINQ simplifies working with XML data & you need not use Xpath or XQuery for reading XML. This tip is about querying XML using LINQ.
="1.0"="utf-8"
<Books>
<Book>
<Subject>
Social Science
</Subject>
<Content>
History,Geography
</Content>
</Book>
<Book>
<Subject>
General Science
</Subject>
<Content>
Biology,Chemistry,Physics
</Content>
</Book>
</Books>
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)
{
listBox1.Items.Add(b.Element("Subject").Value.Trim());
}
}
I am a .Net developer working on C#,Asp.net,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
http://dotnetforyou.wordpress.com/ for more technical articles: