New test.
[mono.git] / mcs / class / System.XML / System.Xml / XmlNamespaceManager.cs
index ea6a8b50523b82c31d1ac28f89330124a7acfa24..50bb0401b5f37be721d0bd707e4b6bdcfff00530 100644 (file)
@@ -170,9 +170,11 @@ namespace System.Xml
                        decls [declPos].Uri = uri;
                }
 
-               internal static string IsValidDeclaration (string prefix, string uri, bool throwException)
+               static string IsValidDeclaration (string prefix, string uri, bool throwException)
                {
                        string message = null;
+                       // It is funky, but it does not check whether prefix
+                       // is equivalent to "xml" in case-insensitive means.
                        if (prefix == PrefixXml && uri != XmlnsXml)
                                message = String.Format ("Prefix \"xml\" can only be bound to the fixed namespace URI \"{0}\". \"{1}\" is invalid.", XmlnsXml, uri);
                        else if (message == null && prefix == "xmlns")
@@ -318,6 +320,16 @@ namespace System.Xml
                }
 
                internal string LookupPrefix (string uri, bool atomizedName)
+               {
+                       return LookupPrefixCore (uri, atomizedName, false);
+               }
+
+               internal string LookupPrefixExclusive (string uri, bool atomizedName)
+               {
+                       return LookupPrefixCore (uri, atomizedName, true);
+               }
+
+               string LookupPrefixCore (string uri, bool atomizedName, bool excludeOverriden)
                {
                        if (uri == null)
                                return null;
@@ -333,7 +345,8 @@ namespace System.Xml
 
                        for (int i = declPos; i >= 0; i--) {
                                if (CompareString (decls [i].Uri, uri, atomizedName) && decls [i].Prefix.Length > 0) // we already looked for ""
-                                       return decls [i].Prefix;
+                                       if (!excludeOverriden || !IsOverriden (i))
+                                               return decls [i].Prefix;
                        }
 
                        // ECMA specifies that this method returns String.Empty
@@ -344,6 +357,17 @@ namespace System.Xml
                        return null;
                }
 
+               bool IsOverriden (int idx)
+               {
+                       if (idx == declPos)
+                               return false;
+                       string prefix = decls [idx + 1].Prefix;
+                       for (int i = idx + 1; i <= declPos; i++)
+                               if ((object) decls [idx].Prefix == prefix)
+                                       return true;
+                       return false;
+               }
+
                public virtual bool PopScope ()
                {
                        if (scopePos == -1)