Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
XmlNamespaceManager Class
Collapse the table of content
Expand the table of content

XmlNamespaceManager Class

Resolves, adds, and removes namespaces to a collection and provides scope management for these namespaces.

Namespace:  System.Xml
Assemblies:   System.Xml (in System.Xml.dll)
  System.Xml.ReaderWriter (in System.Xml.ReaderWriter.dll)

public ref class XmlNamespaceManager : IXmlNamespaceResolver, 
	IEnumerable

The XmlNamespaceManager type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryXmlNamespaceManagerInitializes a new instance of the XmlNamespaceManager class with the specified XmlNameTable.
Top

  NameDescription
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryDefaultNamespaceGets the namespace URI for the default namespace.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibraryNameTableGets the XmlNameTable associated with this object.
Top

  NameDescription
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryAddNamespaceAdds the given namespace to the collection.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibraryFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetEnumeratorReturns an enumerator to use to iterate through the namespaces in the XmlNamespaceManager.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetNamespacesInScopeGets a collection of namespace names keyed by prefix which can be used to enumerate the namespaces currently in scope.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryHasNamespaceGets a value indicating whether the supplied prefix has a namespace defined for the current pushed scope.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryLookupNamespaceGets the namespace URI for the specified prefix.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryLookupPrefixFinds the prefix declared for the given namespace URI.
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibraryMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryPopScopePops a namespace scope off the stack.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryPushScopePushes a namespace scope onto the stack.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryRemoveNamespaceRemoves the given namespace for the given prefix.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibraryToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Public Extension MethodSupported by Portable Class LibraryAsParallel()Overloaded. Enables parallelization of a query. (Defined by ParallelEnumerable.)
Public Extension MethodSupported by Portable Class LibraryAsParallel()Overloaded. (Defined by ParallelEnumerable.)
Public Extension MethodSupported by Portable Class LibraryAsQueryable()Overloaded. Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodSupported by Portable Class LibraryAsQueryable()Overloaded. (Defined by Queryable.)
Public Extension MethodSupported by the XNA FrameworkSupported by Portable Class LibraryCast<TResult>()Overloaded. Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkSupported by Portable Class LibraryCast<TResult>()Overloaded. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkSupported by Portable Class LibraryOfType<TResult>()Overloaded. Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Public Extension MethodSupported by the XNA FrameworkSupported by Portable Class LibraryOfType<TResult>()Overloaded. (Defined by Enumerable.)
Top

For general information about how namespaces are declared and used in XML documents, see Managing Namespaces in an XML Document.

XmlNamespaceManager stores prefixes and namespaces as strings. Here's a summary of management and lookup tasks you can perform with this class. For more information and examples, follow the links to the reference page for each method or property.

To

Use

Add a namespace

AddNamespace method

Remove a namespace

RemoveNamespace method

Find the URI for the default namespace

DefaultNamespace property

Find the URI for a namespace prefix

LookupNamespace method

Find the prefix for a namespace URI

LookupPrefix method

Get a list of namespaces in the current node

GetNamespacesInScope method

Scope a namespace

PushScope and PopScope methods

Check whether a prefix is defined in the current scope

HasNamespace method

Get the name table used to look up prefixes and URIs

NameTable property

To add namespaces to the namespace manager, you create a XmlNamespaceManager object and then use the AddNamespace method. Default prefix and namespace pairs are automatically added to the namespace manager on creation.

When you create the namespace manager, you can specify a name table from the XmlReader, XsltContext, or XmlDocument class, and then use the AddNamespace method to add the namespaces.

You can supply the XmlNamespaceManager object as a parameter to the SelectNodes or SelectSingleNode method of the XmlDocument class to execute XPath query expressions that reference namespace-qualified element and attribute names.

The namespace manager assumes that prefixes and namespaces have already been verified and conform to the W3C Namespaces specification. The namespace manager does not perform any validation.

The namespace manager atomizes the strings when they are added by using the AddNamespace method and when a lookup is performed by using the LookupNamespace or LookupPrefix method.

The namespace manager implements enumeration support in addition to adding and retrieving namespaces. You can loop through the information saved in the namespace manager by using the foreach construct. For example, if you create a namespace manager with the name nsmanager, you can iterate through the table by using foreach (String prefix in nsmanager).

Because the namespace manager provides a string comparison with the prefix and namespaces as objects, there is a performance improvement when using the namespace manager over the direct comparison of a string.

The following code example shows how to bind the prefix xsd with the namespace URI of http://www.w3.org/2001/XMLSchema and add it to the namespace manager:

No code example is currently available or this language may not be supported.

You can then find the namespace by using the LookupNamespace method:

No code example is currently available or this language may not be supported.

The following example creates an XmlNamespaceManager by using the name table from an XML reader:

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft