//
using System.Collections;
+#if NET_2_0
+using System.Collections.Generic;
+#endif
using System.Collections.Specialized;
namespace System.Xml
get { return defaultNamespace == null ? string.Empty : defaultNamespace; }
}
+#if NET_2_0
+ public virtual XmlNameTable NameTable {
+#else
public XmlNameTable NameTable {
+#endif
get { return nameTable; }
}
AddNamespace (prefix, uri, false);
}
-#if NET_2_0
- [Obsolete]
- public virtual void AddNamespace (string prefix, string uri, bool atomizedNames)
-#else
internal virtual void AddNamespace (string prefix, string uri, bool atomizedNames)
-#endif
{
if (prefix == null)
throw new ArgumentNullException ("prefix", "Value cannot be null.");
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")
}
#if NET_2_0
- public virtual IDictionary GetNamespacesInScope (XmlNamespaceScope scope)
+ public virtual IDictionary<string, string> GetNamespacesInScope (XmlNamespaceScope scope)
+ {
+ IDictionary namespaceTable = GetNamespacesInScopeImpl (scope);
+ IDictionary<string, string> namespaces = new Dictionary<string, string>(namespaceTable.Count);
+
+ foreach (DictionaryEntry entry in namespaceTable) {
+ namespaces[(string) entry.Key] = (string) entry.Value;
+ }
+ return namespaces;
+ }
#else
IDictionary IXmlNamespaceResolver.GetNamespacesInScope (XmlNamespaceScope scope)
{
- return GetNamespacesInScope (scope);
+ return GetNamespacesInScopeImpl (scope);
}
-
- internal virtual IDictionary GetNamespacesInScope (XmlNamespaceScope scope)
#endif
+
+ internal virtual IDictionary GetNamespacesInScopeImpl (XmlNamespaceScope scope)
{
Hashtable table = new Hashtable ();
{
return HasNamespace (prefix, false);
}
-
-#if NET_2_0
- [Obsolete]
- public virtual bool HasNamespace (string prefix, bool atomizedNames)
-#else
+
internal virtual bool HasNamespace (string prefix, bool atomizedNames)
-#endif
{
if (prefix == null || count == 0)
return false;
#endif
}
-#if NET_2_0
- [Obsolete]
- public virtual string LookupNamespace (string prefix, bool atomizedNames)
-#else
- string IXmlNamespaceResolver.LookupNamespace (string prefix, bool atomizedNames)
- {
- return LookupNamespace (prefix, atomizedNames);
- }
-
internal virtual string LookupNamespace (string prefix, bool atomizedNames)
-#endif
{
switch (prefix) {
case PrefixXmlns:
return s1 == s2;
}
-#if NET_2_0
- [Obsolete]
- public string LookupPrefix (string uri, bool atomizedName)
-#else
- string IXmlNamespaceResolver.LookupPrefix (string uri, bool atomizedName)
+ internal string LookupPrefix (string uri, bool atomizedName)
{
- return LookupPrefix (uri, atomizedName);
+ return LookupPrefixCore (uri, atomizedName, false);
}
- internal string LookupPrefix (string uri, bool atomizedName)
-#endif
+ 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;
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
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)
RemoveNamespace (prefix, uri, false);
}
-#if NET_2_0
- [Obsolete]
- public virtual void RemoveNamespace (string prefix, string uri, bool atomizedNames)
-#else
internal virtual void RemoveNamespace (string prefix, string uri, bool atomizedNames)
-#endif
{
if (prefix == null)
throw new ArgumentNullException ("prefix");