XML System.Xml [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.Object System.Collections.IEnumerable System.Xml.IXmlNamespaceResolver

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

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

method

Remove a namespace

method

Find the URI for the default namespace

property

Find the URI for a namespace prefix

method

Find the prefix for a namespace URI

method

Get a list of namespaces in the current node

method

Scope a namespace

and methods

Check whether a prefix is defined in the current scope

method

Get the name table used to look up prefixes and URIs

property

To add namespaces to the namespace manager, you create a object and then use the 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 , , or class, and then use the method to add the namespaces.

You can supply the object as a parameter to the or method of the 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 method and when a lookup is performed by using the or 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:

`nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema")` `nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema");`

You can then find the namespace by using the method:

`nsmgr.LookupNamespace("xsd")` `nsmgr.LookupNamespace("xsd");`

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

`Dim reader As New XmlTextReader("myfile.xml") Dim nsmanager As New XmlNamespaceManager(reader.NameTable) nsmanager.AddNamespace("msbooks", "www.microsoft.com/books") nsmanager.PushScope() nsmanager.AddNamespace("msstore", "www.microsoft.com/store") While reader.Read() Console.WriteLine("Reader Prefix:{0}", reader.Prefix) Console.WriteLine("XmlNamespaceManager Prefix:{0}", nsmanager.LookupPrefix(nsmanager.NameTable.Get(reader.NamespaceURI))) End While` `XmlTextReader reader = new XmlTextReader("myfile.xml"); XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable); nsmanager.AddNamespace("msbooks", "www.microsoft.com/books"); nsmanager.PushScope(); nsmanager.AddNamespace("msstore", "www.microsoft.com/store"); while (reader.Read()) { Console.WriteLine("Reader Prefix:{0}", reader.Prefix); Console.WriteLine("XmlNamespaceManager Prefix:{0}", nsmanager.LookupPrefix(nsmanager.NameTable.Get(reader.NamespaceURI))); }`

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

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  is .

  The name table is used to look up prefixes and namespaces. An existing name table with pre-atomized strings can be specified in the constructor. There are several advantages in doing so. For example, if the name table of an object is used, after each read, any namespace and prefix strings pushed into the name table can be re-used by .

  For more information on atomized strings, see .

  If you specify an existing name table, any namespaces in the name table are not automatically added to . You must use and to add or remove namespaces.

  Initializes a new instance of the class with the specified .

  The to use.
  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` is "xml" or "xmlns".

  is , or is .

  The namespace to add.

  does not check and for conformance.

  checks names, including prefixes and namespaces, to ensure they are valid XML names according to the World Wide Web Consortium (W3C) Namespaces specification. is used internally by , so to avoid a duplication of efforts, 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 . 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)

  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

  Adds the given namespace to the collection.

  The prefix to associate with the namespace being added. Use String.Empty to add a default namespace. The namespace to add. 0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

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

  This method is equivalent to calling LookupNamespace(String.Empty).

  Gets the namespace URI for the default namespace.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Collections.IEnumerator

  The following code shows how to use the to view all the namespace pairs stored in the object.

  `Dim nsEnum As IEnumerator = nsmgr.GetEnumerator() Do While nsEnum.MoveNext If nsEnum.Current <> "" Then MsgBox("xmlns:" + nsEnum.Current + "=" + nsmgr.LookupNamespace(nsEnum.Current)) End If Loop`

  Returns an enumerator to use to iterate through the namespaces in the .

  An containing the prefixes stored by the .

  0
- Method
  2.0.0.0
  4.0.0.0
  System.Collections.Generic.IDictionary<System.String,System.String> ``

  The dictionary consists of a collection of namespace names keyed by prefix. It can be used to enumerate the in-scope namespaces. The dictionary is a disconnected copy of the namespace list. It remains unchanged as the current in-scope namespace list changes.

  The following table shows how values affect the namespaces returned by the method.

  XmlNamespaceScope value

  xmlns:xml

  xmlns:xmlns

  xmlns=""

  All

  Yes

  No

  No

  ExcludeXml

  No

  No

  No

  Local

  No

  No

  Yes

  Gets a collection of namespace names keyed by prefix which can be used to enumerate the namespaces currently in scope.

  A collection of namespace and prefix pairs currently in scope.

  An enumeration value that specifies the type of namespace nodes to return.
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean ``

  To determine whether there is a default empty namespace defined, set to String.Empty. A return value of true indicates that there is a default namespace defined in the current scope; false indicates that no default namespace is defined.

  xmlns:x= "" is illegal according to the W3C Namespaces recommendation.

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

  true if there is a namespace defined; otherwise, false.

  The prefix of the namespace you want to find. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String ``

  As described above.

  Override this method to customize the behavior of this method in types derived from the class.

  Gets the namespace URI for the specified prefix.

  Returns the namespace URI for or null if there is no mapped namespace. The returned string is atomized.

  For more information on atomized strings, see the class.

  The prefix whose namespace URI you want to resolve. To match the default namespace, pass String.Empty. 0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String ``

  This method finds the mapped prefix by walking the stack (that is, it looks globally). The supplied string must be atomized for the lookup to succeed. In other words, the supplied string object must exist in the namespace manager's name table ().

  The returned string is also atomized. For more information on atomized strings, see the class.

  Finds the prefix declared for the given namespace URI.

  The matching prefix. If there is no mapped prefix, the method returns String.Empty. If a null value is supplied, then null is returned.

  The namespace to resolve for the prefix. 0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Xml.XmlNameTable

  The used by the current instance.

  The name table is used to look up prefixes and namespace URIs.

  Gets the associated with this object.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Boolean

  When you call this method, all namespaces which were added to (by calling ) since the last call to are removed.

  Pops a namespace scope off the stack.

  true if there are namespace scopes left on the stack; false if there are no more namespaces to pop.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void

  After a call to this method, all namespaces, which are added to (by calling ), belong to the pushed namespace scope.

  Pushes a namespace scope onto the stack.

  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  As described above.

  The namespace removed is from the current namespace scope. Namespaces outside the current scope are ignored. If or does not exist in the collection, this method simply returns.

  Override this method to customize the behavior of this method in types derived from the class.

  is , or is . The namespace to remove for the given prefix. The namespace removed is from the current namespace scope. Namespaces outside the current scope are ignored.

  Removes the given namespace for the given prefix.

  The prefix for the namespace The namespace to remove for the given prefix. The namespace removed is from the current namespace scope. Namespaces outside the current scope are ignored. 0
- Method
  System.Collections.IDictionary `` To be added. To be added. To be added. To be added. 1.0.5000.0
0