+ if (NsNode == nsNodeXml)
+ // Current namespace is "xml", so there should be no more namespace nodes.
+ return false;
+
+ if (NsNode == null)
+ return false;
+
+ // Get current attribute's position.
+ int pos = 0;
+ XmlElement owner = ((XmlAttribute) NsNode).OwnerElement;
+ if (owner == null)
+ return false;
+
+ int count = owner.Attributes.Count;
+ for(; pos < count; pos++)
+ if (owner.Attributes [pos] == NsNode)
+ break;
+ if (pos == count)
+ return false; // Where is current attribute? Maybe removed.
+
+ // Find next namespace from the same element as current ns node.
+ for(pos++; pos < count; pos++) {
+ if (owner.Attributes [pos].NamespaceURI == Xmlns) {
+ XmlAttribute a = owner.Attributes [pos];
+ if (CheckNsNameAppearance (a.Name, a.Value))
+ continue;
+ NsNode = a;
+ return true;
+ }
+ }
+
+ // If not found more, then find from ancestors.
+ // But if scope is Local, then it returns false here.
+ if (namespaceScope == XPathNamespaceScope.Local)
+ return false;
+ owner = owner.ParentNode as XmlElement;
+ while (owner != null) {
+ for (int i = 0; i < owner.Attributes.Count; i++) {
+ XmlAttribute attr = owner.Attributes [i];
+ if (attr.NamespaceURI == Xmlns) {
+ if (CheckNsNameAppearance (attr.Name, attr.Value))
+ continue;
+ NsNode = attr;
+ return true;
+ }
+ }
+ owner = owner.ParentNode as XmlElement;
+ }
+
+ if (namespaceScope == XPathNamespaceScope.All) {
+ if (CheckNsNameAppearance (nsNodeXml.Name, nsNodeXml.Value))
+ return false;
+ NsNode = nsNodeXml;
+ return true;
+ }
+ return false;