Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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

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

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"),
IEnumerable<XAttribute> listOfAttributes =
    from att in val.Attributes()
    select att;
foreach (XAttribute a in listOfAttributes)

This code produces the following output:

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.