Export (0) Print
Expand All

XElement.Attribute Method

Returns the XAttribute of this XElement that has the specified XName.

Namespace:  System.Xml.Linq
Assemblies:   System.Xml.Linq (in System.Xml.Linq.dll)
  System.Xml.XDocument (in System.Xml.XDocument.dll)

member Attribute : 
        name:XName -> XAttribute

Parameters

name
Type: System.Xml.Linq.XName

The XName of the XAttribute to get.

Return Value

Type: System.Xml.Linq.XAttribute
An XAttribute that has the specified XName; a null reference (Nothing in Visual Basic) if there is no attribute with the specified name.

Some axis methods return collections of elements or attributes. This method returns only a single attribute. Sometimes this is referred to as a singleton (in contrast to a collection).

Visual Basic users can use the integrated attribute axis to retrieve the value of an attribute with a specified name.

The following example creates an element with an attribute. It then retrieves the attribute using this method.

No code example is currently available or this language may not be supported.

This example produces the following output:

Att="attribute content"

The following is the same example, but in this case the XML is in a namespace. For more information, see Working with XML Namespaces.

No code example is currently available or this language may not be supported.

This example produces the following output:

aw:Att="attribute content"

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft