Query XML using LINQ

Your Ad Here

Query XML
Example below given shows that how easy it is to  displays the ease with which one
can interact with and query Extensible Markup Language (XML) data utilizing the LINQ to XML API.
You should pay particular attention to how I construct the XML data into an object named books that
I can programmatically interact with.

A Simple XML Query Using LINQ to XML

using System;
using System.Linq;
using System.Xml.Linq;

XElement books = XElement.Parse(
<title>Learn Integrated Query in C#  2008</title>
<author>Kulveer Singh</author>
<title>Pro WF: Windows Workflow in .NET 3.0</title>
<author>Bill Gates</author>
<title>Learn how to make Money </title>
var titles = from book in books.Elements("book")
where (string) book.Element("author") == "Joe Rattz"
select book.Element("title");
foreach(var title in titles)

Namespace system.linq and system.xml.linq are included to run this example. which is required by linq to run.Did you notice how I parsed the XML data into an object of type XElement? Nowhere did I create an XmlDocument. Among the benefits of LINQ to XML are the extensions made to the XML API. Now instead of being XmlDocument-centric as the W3C Document Object Model (DOM) XML API requires,LINQ to XML allows the developer to interact at the element level using the XElement class.

Posted in |


  1. Anonymous Says:

    free por [url=http://pornushi.ru/english-version/young-girls-pussys/page_754.htm]brutalne porno fisting[/url]