| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- // -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
- //
- // System.Xml.XmlNamespaceManager.cs
- //
- // Author:
- // Jason Diamond ([email protected])
- //
- // (C) 2001 Jason Diamond http://injektilo.org/
- //
- using System.Collections;
- namespace System.Xml
- {
- public class XmlNamespaceManager : IEnumerable
- {
- private XmlNameTable _NameTable;
- NamespaceScope _Top;
- public XmlNamespaceManager(XmlNameTable nameTable)
- {
- _NameTable = nameTable;
- PushScope();
- }
- public virtual string DefaultNamespace
- {
- get
- {
- return LookupNamespace(String.Empty);
- }
- }
- public XmlNameTable NameTable
- {
- get
- {
- return _NameTable;
- }
- }
- public virtual void AddNamespace(string prefix, string uri)
- {
- if (prefix == null)
- {
- throw new ArgumentNullException("prefix", "Value cannot be null.");
- }
- if (uri == null)
- {
- throw new ArgumentNullException("uri", "Value cannot be null.");
- }
- if (prefix.Length > 2 && prefix.Substring(0, 3).ToLower() == "xml")
- {
- throw new ArgumentException("Prefixes beginning with \"xml\" (regardless of whether the characters are uppercase, lowercase, or some combination thereof) are reserved for use by XML.", "prefix");
- }
- if (_Top.Namespaces == null)
- {
- _Top.Namespaces = new Hashtable();
- }
- _Top.Namespaces.Add(prefix, uri);
- }
- public virtual IEnumerator GetEnumerator()
- {
- // TODO: implement me.
- throw new NotImplementedException();
- }
- public virtual bool HasNamespace(string prefix)
- {
- NamespaceScope scope = _Top;
- while (scope != null)
- {
- if (scope.Namespaces != null)
- {
- if (scope.Namespaces.Contains(prefix))
- {
- return true;
- }
- }
- scope = scope.Next;
- }
- return false;
- }
- public virtual string LookupNamespace(string prefix)
- {
- NamespaceScope scope = _Top;
- while (scope != null)
- {
- if (scope.Namespaces != null)
- {
- if (scope.Namespaces.Contains(prefix))
- {
- string uri = scope.Namespaces[prefix] as string;
- return uri;
- }
- }
- scope = scope.Next;
- }
- switch (prefix)
- {
- case "xmlns":
- return "http://www.w3.org/2000/xmlns/";
- case "xml":
- return "http://www.w3.org/XML/1998/namespace";
- case "":
- return String.Empty;
- }
- return null;
- }
- public virtual string LookupPrefix(string uri)
- {
- // TODO: implement me.
- throw new NotImplementedException();
- }
- public virtual bool PopScope()
- {
- if (_Top != null)
- {
- _Top = _Top.Next;
- return true;
- }
- return false;
- }
- public virtual void PushScope()
- {
- NamespaceScope newScope = new NamespaceScope();
- newScope.Next = _Top;
- _Top = newScope;
- }
- public virtual void RemoveNamespace(string prefix, string uri)
- {
- // TODO: implement me.
- throw new NotImplementedException();
- }
- }
- internal class NamespaceScope
- {
- internal NamespaceScope Next;
- internal Hashtable Namespaces;
- }
- }
|