3.2. Querying XML
Since LINQ to XML supports the LINQ standard query operators, an XML document can be loaded in memory and then queried with the usual LINQ query syntax.
Let's start by analyzing a simple query using a couple of important LINQ to XML classes. Listing 3-1 is the XML representation of our People database.
Example 3-1. The XML Representation of the People Database
<?xml version="1.0" encoding="utf-8" ?> <people> <!--Person section--> <person> <id>1</id> <firstname>Carl</firstname> <lastname>Lewis</lastname> <idrole>1</idrole> </person> <person> <id>2</id> <firstname>Tom</firstname> <lastname>Gray</lastname> <idrole>2</idrole> </person> <person> <id>3</id> <firstname>Mary</firstname> <lastname>Grant</lastname> <idrole>2</idrole> ... |
Get LINQ for Visual 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.