public string LookupAttributePrefix(string ns)
{
if (_lastNameSpace != null && _lastNameSpace.Uri == ns && _lastNameSpace.Prefix.Length != 0)
return _lastNameSpace.Prefix;
int nsCount = _nsCount;
for (int i = nsCount - 1; i >= _nsTop; i--)
{
Namespace nameSpace = _namespaces[i];
if (object.ReferenceEquals(nameSpace.Uri, ns))
{
string prefix = nameSpace.Prefix;
if (prefix.Length != 0)
{
// Make sure that the prefix refers to the namespace in scope
bool declared = false;
for (int j = i + 1; j < nsCount; j++)
{
if (_namespaces[j].Prefix == prefix)
{
declared = true;
break;
}
}
if (!declared)
{
_lastNameSpace = nameSpace;
return prefix;
}
}
}
}
for (int i = nsCount - 1; i >= _nsTop; i--)
{
Namespace nameSpace = _namespaces[i];
if (nameSpace.Uri == ns)
{
string prefix = nameSpace.Prefix;
if (prefix.Length != 0)
{
// Make sure that the prefix refers to the namespace in scope
bool declared = false;
for (int j = i + 1; j < nsCount; j++)
{
if (_namespaces[j].Prefix == prefix)
{
declared = true;
break;
}
}
if (!declared)
{
_lastNameSpace = nameSpace;
return prefix;
}
}
}
}
if (ns.Length == 0)
return string.Empty;
return null;
}