XElement.Attributes Method

Returns a collection of attributes of this element.

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

'Declaration
Public Function Attributes As IEnumerable(Of XAttribute)

Return Value

Type: System.Collections.Generic.IEnumerable(Of XAttribute)
An IEnumerable(Of 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.


Dim output As New StringBuilder
Dim xmlTree As XElement = <Root Att1="content1" Att2="content2"/>

Dim attList As IEnumerable(Of XAttribute) = _
From at In xmlTree.Attributes() _
Select at

For Each att In attList
    output.Append(att)
    output.Append(Environment.NewLine)
Next


OutputTextBlock.Text = output.ToString()


Silverlight

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

ADD
Show: