System.Xml.XmlNamespaceManager Class

public class XmlNamespaceManager : IEnumerable

Base Types

Object
  XmlNamespaceManager

This type implements IEnumerable.

Assembly

System.Xml

Library

XML

Summary

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.

Description

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.

PrefixNamespace
xmlnshttp://www.w3.org/2000/xmlns/ (the xmlns prefix namespace)
xmlhttp://www.w3.org/XML/1998/namespace (The XML namespace)
System.String.EmptySystem.String.Empty. The empty namespace can be reassigned a different prefix. For example, xmlns="" defines the default namespace to be the empty namespace.

See Also

System.Xml Namespace

Members

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


XmlNamespaceManager Constructor

public XmlNamespaceManager(XmlNameTable nameTable);

Summary

Constructs and initializes a new instance of the XmlNamespaceManager class.

Parameters

nameTable
The XmlNameTable to use.

Exceptions

Exception TypeCondition
ArgumentNullExceptionnameTable is null .

Description

[Note: nameTable is used to look up prefixes and namespaces.

]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.AddNamespace Method

public virtual void AddNamespace(string prefix, string uri);

Summary

Adds the given namespace to the collection of namespaces maintained by the current instance in System.Xml.XmlNamespaceManager.NameTable.

Parameters

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.

Exceptions

Exception TypeCondition
ArgumentExceptionprefix is "xml" or "xmlns".
ArgumentNullExceptionprefix is null , or uri is null .

Description

[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. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.GetEnumerator Method

public virtual IEnumerator GetEnumerator();

Summary

Provides support for iteration over the collection of namespaces maintained by the current instance.

Return Value

A IEnumerator.

Description

[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. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.HasNamespace Method

public virtual bool HasNamespace(string prefix);

Summary

Gets a value indicating whether the supplied prefix has a namespace defined for the current pushed scope.

Parameters

prefix
A String containing the prefix of the namespace to find.

Return Value

A Boolean where true indicates there is a namespace defined; otherwise, false . If prefix is null , returns false .

Description

[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. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.LookupNamespace Method

public virtual string LookupNamespace(string prefix);

Summary

Gets the namespace URI associated with the specified prefix.

Parameters

prefix
A String containing the prefix whose namespace URI to resolve. To match the default namespace, pass System.String.Empty.

Return Value

A String containing the namespace URI for prefix, or null if there is no mapped namespace.

Description

[Behaviors: As described above. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.LookupPrefix Method

public virtual string LookupPrefix(string uri);

Summary

Gets the prefix associated with the given namespace URI.

Parameters

uri
A String containing the namespace to resolve for the prefix.

Return Value

A String containing the matching prefix. If there is no mapped prefix, this method returns null . If a null value is supplied, then null is returned.

Description

[Behaviors: As described above. ]

[Overrides: Override this method to customize the behavior of this method in types derived from the XmlNamespaceManager class. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.PopScope Method

public virtual bool PopScope();

Summary

Pops a namespace scope off the stack.

Return Value

A Boolean where true indicates a namespace scope was popped off the stack; false indicates there were no namespaces scopes to pop.

Description

[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. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.PushScope Method

public virtual void PushScope();

Summary

Pushes a namespace scope onto the stack.

Description

[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. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.RemoveNamespace Method

public virtual void RemoveNamespace(string prefix, string uri);

Summary

Removes the specified namespace associated with the specified prefix from the namespace collection maintained by the current instance.

Parameters

prefix
A String specifying the prefix.
uri
A String specifying the namespace to remove.

Exceptions

Exception TypeCondition
ArgumentNullExceptionprefix is null , or uri is null .

Description

[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. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.DefaultNamespace Property

public virtual string DefaultNamespace { get; }

Summary

Gets the namespace URI for the default namespace.

Property Value

A String containing the namespace URI for the default namespace, or System.String.Empty if there is no default namespace.

Description

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. ]

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace

XmlNamespaceManager.NameTable Property

public XmlNameTable NameTable { get; }

Summary

Gets the name table used by the current instance to look up prefixes and namespace URIs.

Property Value

The XmlNameTable used by the current instance.

Description

This property is read-only.

See Also

System.Xml.XmlNamespaceManager Class, System.Xml Namespace