Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlReader.GetAttribute Method (Int32)

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 abstract string GetAttribute(
	int i
)

Parameters

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.

ExceptionCondition
ArgumentOutOfRangeException

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



StringBuilder output = new StringBuilder();

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

// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
{
    reader.ReadToFollowing("Item");
    OutputTextBlock.Text = reader.GetAttribute(0);
}


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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft