Basic Queries (LINQ to XML) (C#)

This section provides examples of basic LINQ to XML queries.

In This Section

Topic Description
How to: Find an Element with a Specific Attribute (C#) Shows how to find a particular element that has an attribute that has a specific value.
How to: Find an Element with a Specific Child Element (C#) Shows how to find a particular element that has a child element that has a specific value.
Querying an XDocument vs. Querying an XElement (C#) Explains the differences between writing queries on an XML tree that is rooted in XElement and writing queries on an XML tree that is rooted in XDocument.
How to: Find Descendants with a Specific Element Name (C#) Shows how to find all the descendants of an element that have a specific name. This example uses the Descendants axis.
How to: Find a Single Descendant Using the Descendants Method (C#) Shows how to use the Descendants axis method to find a single uniquely named element.
How to: Write Queries with Complex Filtering (C#) Shows how to write a query with a more complex filter.
How to: Filter on an Optional Element (C#) Shows how to find nodes in an irregularly shaped tree.
How to: Find All Nodes in a Namespace (C#) Shows how to find all nodes that are in a specific namespace.
How to: Sort Elements (C#) Shows how to write a query that sorts its results.
How to: Sort Elements on Multiple Keys (C#) Shows how to sort on multiple keys.
How to: Calculate Intermediate Values (C#) Shows how to use the Let clause to calculate intermediate values in a LINQ to XML query.
How to: Write a Query that Finds Elements Based on Context (C#) Shows how to select elements based on other elements in the tree.
How to: Debug Empty Query Results Sets (C#) Shows the appropriate fix when debugging queries on XML that is in a default namespace.

See Also