XElement.Attributes Method

Returns a collection of attributes of this element.

Namespace:  System.Xml.Linq
Assembly:  System.Xml.Linq (in System.Xml.Linq.dll)

public IEnumerable<XAttribute> Attributes()

Return Value

Type: System.Collections.Generic.IEnumerable<XAttribute>
An IEnumerable<T> of XAttribute of attributes of this element.

The attributes in the returned collection are in the order that they were added to the element. If the XML tree was parsed from XML, the attributes are returned in document order.

This method uses deferred execution.

The following example creates an element with two attributes. It then uses this axis method to retrieve all attributes of the element.

StringBuilder output = new StringBuilder();
XElement xmlTree = new XElement("Root",
    new XAttribute("Att1", "content1"),
    new XAttribute("Att2", "content2")
IEnumerable<XAttribute> attList =
    from at in xmlTree.Attributes()
    select at;
foreach (XAttribute att in attList)
    output.Append(att + Environment.NewLine);

OutputTextBlock.Text = output.ToString();


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions