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.
Assembly: System.Xml (in System.Xml.dll)
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.StringThe value of the specified attribute. This method does not move the reader.
| Exception | Condition |
|---|---|
| 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); }
Show: