In the previous LINQ to XML chapters, I demonstrated the core principles needed to perform XML queries using LINQ to XML. However, most of the examples are specifically designed to demonstrate an operator or a property. In this section, I want to provide some examples that are more solution oriented.

No Reaching

In the previous chapters, many of the examples would reach down into the XML hierarchy to obtain a reference to a particular element by calling the Element or Elements operators recursively until the desired element was reached.

For instance, many of the examples contained lines such as this:

IEnumerable<XElement> elements =

In this statement, I start at the ...

Get Pro LINQ: Language Integrated Query in C# 2008 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.