Gets the value of the attribute with the specified name and namespace.
[Visual Basic] Overloads Overrides Public Function GetAttribute( _ ByVal name As String, _ ByVal namespaceURI As String _ ) As String [C#] public override string GetAttribute( string name, string namespaceURI ); [C++] public: override String* GetAttribute( String* name, String* namespaceURI ); [JScript] public override function GetAttribute( name : String, namespaceURI : String ) : String;
The value of the specified attribute. If the attribute is not found, null is returned.
Exception Type | Condition |
---|---|
ArgumentException | The attribute specified by name and namespaceURI properties cannot be found in the current node. |
The following XML contains an attribute in a specific namespace:
<test xmlns:dt="urn:datatypes" dt:type="int"/>
You can lookup the dt:type attribute using one argument (using Prefix+LocalName) or using two arguments (LocalName and NamespaceURI):
String dt = reader.GetAttribute("dt:type");
String dt2 = reader.GetAttribute("type","urn:datatypes");
Note that the xmlns attributes have no namespace URI; therefore, the only way to look them up is with the short version
String dt3 = reader.GetAttribute("xmlns:dt");
You can also get this information using the Prefix property.
XmlTextReader Class | XmlTextReader Members | System.NewXml Namespace | XmlTextReader.GetAttribute Overload List