GetAttribute Method (Int32)
Collapse the table of content
Expand the table of content

XmlReader.GetAttribute Method (Int32)

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

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);
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft