public override string GetAttribute(string localName, string namespaceURI)
{
if (null == localName)
{
throw new ArgumentNullException("localName");
}
// reader allows calling GetAttribute, even when positioned inside attributes
XPathNavigator nav = _nav;
switch (nav.NodeType)
{
case XPathNodeType.Element:
break;
case XPathNodeType.Attribute:
nav = nav.Clone();
if (!nav.MoveToParent())
{
return(null);
}
break;
default:
return(null);
}
// are they really looking for a namespace-decl?
if (namespaceURI == XmlConst.ReservedNsXmlNs)
{
if (localName == "xmlns")
{
localName = string.Empty;
}
return(nav.GetNamespace(localName));
}
if (null == namespaceURI)
{
namespaceURI = string.Empty;
}
// We need to clone the navigator and move the clone to the attribute to see whether the attribute exists,
// because XPathNavigator.GetAttribute return string.Empty for both when the the attribute is not there or when
// it has an empty value. XmlReader.GetAttribute must return null if the attribute does not exist.
if ((object)nav == (object)_nav)
{
nav = nav.Clone();
}
if (nav.MoveToAttribute(localName, namespaceURI))
{
return(nav.Value);
}
else
{
return(null);
}
}