XmlReader.GetAttribute Method (String)
[ 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 Name.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- name
- Type: System.String
The qualified name of the attribute.
Return Value
Type: System.StringThe value of the specified attribute. If the attribute is not found or the value is String.Empty, null is returned.
| Exception | Condition |
|---|---|
| ArgumentNullException | name is null. |
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("PartNumber"); }
Show: