public class XmlNamespaceManager : IEnumerable
Object
XmlNamespaceManagerThis type implements IEnumerable.
System.Xml
XML
Resolves, adds, and removes namespaces in a collection and provides scope management for these namespaces. This class is used by the XmlReader and XmlTextReader classes.
This class stores prefixes and namespaces as unique String objects.XmlNamespaceManager assumes all prefixes and namespaces are valid.
If the prefix and namespace already exist within the current scope, they will replace the existing prefix/namespace combination. The same prefix and namespace combination can exist across different scopes.
The following prefix/namespace pairs are added by default to the XmlNamespaceManager. They can be determined at any scope.
Prefix Namespace xmlns http://www.w3.org/2000/xmlns/ (the xmlns prefix namespace) xml http://www.w3.org/XML/1998/namespace (The XML namespace) System.String.Empty System.String.Empty. The empty namespace can be reassigned a different prefix. For example, xmlns=""
defines the default namespace to be the empty namespace.
System.Xml Namespace
XmlNamespaceManager Constructors
XmlNamespaceManager Constructor
XmlNamespaceManager Methods
XmlNamespaceManager.AddNamespace Method
XmlNamespaceManager.GetEnumerator Method
XmlNamespaceManager.HasNamespace Method
XmlNamespaceManager.LookupNamespace Method
XmlNamespaceManager.LookupPrefix Method
XmlNamespaceManager.PopScope Method
XmlNamespaceManager.PushScope Method
XmlNamespaceManager.RemoveNamespace Method
XmlNamespaceManager Properties
XmlNamespaceManager.DefaultNamespace Property
XmlNamespaceManager.NameTable Property
public XmlNamespaceManager(XmlNameTable nameTable);
Constructs and initializes a new instance of the XmlNamespaceManager class.
- nameTable
- The XmlNameTable to use.
Exception Type Condition ArgumentNullException nameTable is null
.
[Note: nameTable is used to look up prefixes and namespaces.]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual void AddNamespace(string prefix, string uri);
Adds the given namespace to the collection of namespaces maintained by the current instance in System.Xml.XmlNamespaceManager.NameTable.
- prefix
- A String specifying the prefix to associate with the namespace being added. Use System.String.Empty to add a default namespace.
- uri
- A String specifying the namespace to add.
Exception Type Condition ArgumentException prefix is "xml" or "xmlns". ArgumentNullException prefix is null
, or uri isnull
.
[Note: The same prefix and namespace combination can exist across different scopes.]
[Behaviors: As described above.]
[Default: This method assumes all prefixes and namespaces are valid but does not check prefix and uri for conformance to the W3C specification.
If the specified prefix/namespace combination already exists within the current scope, their String instances will be replaced in System.Xml.XmlNamespaceManager.NameTable with the new String instances of prefix and uri.
]
[Overrides: Override this method to check prefix and uri for conformance to the W3C specification. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual IEnumerator GetEnumerator();
Provides support for iteration over the collection of namespaces maintained by the current instance.
A IEnumerator.
[Behaviors: As described above. ]
[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]
[Usage: Use this method to iterate through the collection of namespaces in System.Xml.XmlNamespaceManager.NameTable. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual bool HasNamespace(string prefix);
Gets a value indicating whether the supplied prefix has a namespace defined for the current pushed scope.
- prefix
- A String containing the prefix of the namespace to find.
A Boolean wheretrue
indicates there is a namespace defined; otherwise,false
. If prefix isnull
, returnsfalse
.
[Behaviors: As described above. ]
[Default: When prefix is set to System.String.Empty, this method returns
true
to indicate a default empty namespace is defined in the current scope. ]
[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual string LookupNamespace(string prefix);
Gets the namespace URI associated with the specified prefix.
- prefix
- A String containing the prefix whose namespace URI to resolve. To match the default namespace, pass System.String.Empty.
A String containing the namespace URI for prefix, ornull
if there is no mapped namespace.
[Behaviors: As described above. ]
[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual string LookupPrefix(string uri);
Gets the prefix associated with the given namespace URI.
- uri
- A String containing the namespace to resolve for the prefix.
A String containing the matching prefix. If there is no mapped prefix, this method returns System.String.Empty. If anull
value is supplied, thennull
is returned.
[Behaviors: As described above. ]
[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual bool PopScope();
Pops a namespace scope off the stack.
A Boolean wheretrue
indicates a namespace scope was popped off the stack;false
indicates there were no namespaces scopes to pop.
[Behaviors: As described above. ]
[Default: This method removes all the namespaces that were added to the collection (by calling System.Xml.XmlNamespaceManager.AddNamespace(System.String,System.String)) since the last call to the System.Xml.XmlNamespaceManager.PopScope method. ]
[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual void PushScope();
Pushes a namespace scope onto the stack.
[Behaviors: As described above. ]
[Default: This method associates the pushed namespace scope with all the namespaces added to the collection (by calling System.Xml.XmlNamespaceManager.AddNamespace(System.String,System.String)) since the last call to the System.Xml.XmlNamespaceManager.PushScope method.]
[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual void RemoveNamespace(string prefix, string uri);
Removes the specified namespace associated with the specified prefix from the namespace collection maintained by the current instance.
- prefix
- A String specifying the prefix.
- uri
- A String specifying the namespace to remove.
Exception Type Condition ArgumentNullException prefix is null
, or uri isnull
.
[Behaviors: As described above. ]
[Default: The namespace removed is from the current namespace scope. Namespaces outside the current scope are ignored. If prefix or uri does not exist in the collection, this method simply returns. ]
[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public virtual string DefaultNamespace { get; }
Gets the namespace URI for the default namespace.
A String containing the namespace URI for the default namespace, or System.String.Empty if there is no default namespace.
This property is read-only.[Behaviors: As described above. ]
[Default: This method is equivalent to calling System.Xml.XmlNamespaceManager.LookupNamespace(System.String) (System.String.Empty). ]
[Overrides: Override this property to customize the behavior of this property in types derived from the XmlNamespaceManager class. ]
System.Xml.XmlNamespaceManager Class, System.Xml Namespace
public XmlNameTable NameTable { get; }
Gets the name table used by the current instance to look up prefixes and namespace URIs.
The XmlNameTable used by the current instance.
This property is read-only.
System.Xml.XmlNamespaceManager Class, System.Xml Namespace