Attributes Method
Collapse the table of content
Expand the table of content

XElement.Attributes Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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()


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft