System.Xml.XmlNamespaceManager.AddNamespace Method

Adds the given namespace to the collection.

Syntax

public virtual void AddNamespace (string prefix, string uri)

Parameters

uri
The namespace to add.
prefix
The prefix to associate with the namespace being added. Use String.Empty to add a default namespace.
uri
The namespace to add.

Exceptions

TypeReason
ArgumentException prefix is "xml" or "xmlns".
ArgumentNullException prefix is null, or uri is null.

Remarks

System.Xml.XmlNamespaceManager does not check prefix and uri for conformance.

System.Xml.XmlReader checks names, including prefixes and namespaces, to ensure they are valid XML names according to the World Wide Web Consortium (W3C) tp://www.w3.org/TR/REC-xml-names/. System.Xml.XmlNamespaceManager is used internally by System.Xml.XmlReader, so to avoid a duplication of efforts, System.Xml.XmlNamespaceManager assumes all prefixes and namespaces are valid.

If the prefix and namespace already exist within the current scope, the new prefix and namespace pair 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 System.Xml.XmlNamespaceManager. They can be determined at any scope.

xmlns

http://www.w3.org/2000/xmlns/ (the xmlns prefix namespace)

xml

http://www.w3.org/XML/1998/namespace (the XML namespace)

String.Empty

String.Empty (the empty namespace). This value can be reassigned a different prefix. For example, xmlns="" defines the default namespace to be the empty namespace

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0