LINQ : LINQ to XML

LINQ to XML offers a slightly different syntax that operates on XML data, allowing query and data manipulation. A particular type of support for LINQ to XML is offered by Visual Basic
9.0, which includes XML literals in the language. This enhanced support simplifies the code necessary to manipulate XML data. In fact, you can write such a query in Visual Basic 9.0:

Dim book = _
<Book Title="Introducing LINQ">
<%= From person In team _
Where person.Role = "Author" _
Select <Author><%= person.Name %></Author> %>
</Book>

This query corresponds to the following C# 3.0 syntax:
dim book =
new XElement( "Book",
new XAttribute( "Title", "Introducing LINQ" ),
from person in team
where person.Role == "Author"
select new XElement( "Author", person.Name ) );

No comments:

Post a Comment