Query XML using LINQ
Posted On Saturday, August 22, 2009 at at 3:21 PM by test
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(
@"<books>
<book>
<title>Learn Integrated Query in C# 2008</title>
<author>Kulveer Singh</author>
</book>
<book>
<title>Pro WF: Windows Workflow in .NET 3.0</title>
<author>Bill Gates</author>
</book>
<book>
<title>Learn how to make Money </title>
<author>MoneyMaker</author>
</book>
</books>");
var titles = from book in books.Elements("book")
where (string) book.Element("author") == "Joe Rattz"
select book.Element("title");
foreach(var title in titles)
Console.WriteLine(title.Value);
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.
free por [url=http://pornushi.ru/english-version/young-girls-pussys/page_754.htm]brutalne porno fisting[/url]