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 MustOverride Function GetAttribute ( _
    name As String _
) As String
public abstract string GetAttribute(
    string name


Return Value

Type: System..::.String
The value of the specified attribute. If the attribute is not found or the value is String.Empty, nullNothingnullptra null reference (Nothing in Visual Basic) is returned.


Exception Condition

name is nullNothingnullptra null reference (Nothing in Visual Basic).


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


Dim output As New StringBuilder()

Dim xmlString As String = _
        "<PurchaseOrder>" & _
            "<Items>" & _
                "<Item PartNumber='872-AA'>" & _
                    "<ProductName>Lawnmower</ProductName>" & _
                    "<Quantity>1</Quantity>" & _
                    "<USPrice>148.95</USPrice>" & _
                    "<Comment>Confirm this is electric</Comment>" & _
                "</Item>" & _
            "</Items>" & _

' Create an XmlReader
Using reader As XmlReader = XmlReader.Create(New StringReader(xmlString))
    OutputTextBlock.Text = reader.GetAttribute("PartNumber")
End Using
StringBuilder output = new StringBuilder();

String xmlString =
      <Item PartNumber='872-AA'>
        <Comment>Confirm this is electric</Comment>

// Create an XmlReader
using (XmlReader reader = XmlReader.Create(new StringReader(xmlString)))
    OutputTextBlock.Text = reader.GetAttribute("PartNumber");

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0


Windows Phone

See Also


XmlReader Class

GetAttribute Overload

System.Xml Namespace