This documentation is archived and is not being maintained.

How to: Retrieve a Collection of Attributes (LINQ to XML)

This topic introduces the Attributes method. This method retrieves the attributes of an element.

Example

The following example shows how to iterate through the collection of attributes of an element.

XElement val = new XElement("Value",
    new XAttribute("ID", "1243"),
    new XAttribute("Type", "int"),
    new XAttribute("ConvertableTo", "double"),
    "100");
IEnumerable<XAttribute> listOfAttributes =
    from att in val.Attributes()
    select att;
foreach (XAttribute a in listOfAttributes)
    Console.WriteLine(a);

This code produces the following output:

ID="1243"
Type="int"
ConvertableTo="double"

See Also

Concepts

LINQ to XML Axes




Build Date:

2012-08-02
Show: