O'Reilly logo

LINQ for Visual C# 2008 by Fabio Claudio Ferracchiati

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required