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

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.

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

public abstract string GetAttribute(
	string name
)

Parameters

name
Type: System.String
The qualified name of the attribute.

Return Value

Type: System.String
The value of the specified attribute. If the attribute is not found or the value is String.Empty, null is returned.

ExceptionCondition
ArgumentNullException

name is null.

This method does not move the reader.

If the reader is positioned on a DocumentType node, this method can be used to get the PUBLIC and SYSTEM literals, for example, reader.GetAttribute("PUBLIC")


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


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft