Queries

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 =
  xDocument.Element("BookParticipants").Elements("BookParticipant");

In this statement, I start at the ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.