LINQ Programming by Joe Mayo

LINQ Programming by Joe Mayo

Author:Joe Mayo
Language: eng
Format: epub
Publisher: McGraw-Hill Education
Published: 2009-04-15T04:00:00+00:00


var zune =

(from prod in products.Elements(“product”)

where prod.Attribute(“productID”).Value == “1”

select prod)

.Single();

Console.WriteLine(zune);

This filter used prod.Attribute(“productID”).Value to return the product with a productID, attribute equal to 1.

In addition to the Elements method, LINQ to XML offers many axes methods for querying XML, as discussed in the next section.

LINQ to XML Axis Methods

An axis is a point of reference from which to view related elements. To demonstrate how they work, we’ll use the following XML document, products.xml, to show how each of the LINQ to SQL axis methods works:

<?xml version=“1.0” encoding=“utf-8”?>

<products>

<product productID=“1”>

<name>Zune</name>

<listPrice>250.00</listPrice>

</product>

<product productID=“2”>

<name>iPod</name>

<listPrice>299.00</listPrice>

</product>

</products>



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.