Export (0) Print
Expand All

XmlReader.GetAttribute Method (String)

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


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.

Community Additions

ADD
Show:
© 2014 Microsoft