XmlReader.GetAttribute Method (Int32)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

When overridden in a derived class, gets the value of the attribute with the specified index.

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


Public MustOverride Function GetAttribute ( _
    i As Integer _
) As String
public abstract string GetAttribute(
    int i


  • i
    Type: System.Int32
    The index of the attribute. The index is zero-based. (The first attribute has index 0.)

Return Value

Type: System.String
The value of the specified attribute. This method does not move the reader.


Exception Condition

i is out of range. Must be non-negative and less than the size of the attribute collection.


Dim output As New StringBuilder()

Dim xmlString As String = _
        "<PurchaseOrder>" & _
            "<Items>" & _
                "<Item PartNumber='872-AA'>" & _
                    "<ProductName>Lawnmower</ProductName>" & _
                    "<Quantity>1</Quantity>" & _
                    "<USPrice>148.95</USPrice>" & _
                    "<Comment>Confirm this is electric</Comment>" & _
                "</Item>" & _
            "</Items>" & _

' Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString)) '

    OutputTextBlock.Text = reader.GetAttribute(0)
End Using

StringBuilder output = new StringBuilder();

String xmlString =
      <Item PartNumber='872-AA'>
        <Comment>Confirm this is electric</Comment>

// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
    OutputTextBlock.Text = reader.GetAttribute(0);

Version Information


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.