Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlNamespaceManager Constructor

Initializes a new instance of the XmlNamespaceManager class with the specified XmlNameTable.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public XmlNamespaceManager(
	XmlNameTable nameTable
)

Parameters

nameTable
Type: System.Xml.XmlNameTable
The XmlNameTable to use.
ExceptionCondition
NullReferenceException

nameTable is null.

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 XmlReader object is used, after each read, any namespace and prefix strings pushed into the name table can be re-used by XmlNamespaceManager.

For more information on atomized strings, see XmlNameTable.

NoteNote:

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



                StringBuilder output = new StringBuilder();

                // Create the string containing the XML to read.
                String xmlFrag =
                    @"<root>
                        <data>
	                        <items>
		                        <item id='1'>
		                        </item>
	                        </items>
                        </data>
                        </root>";

                using (XmlReader reader = XmlReader.Create(new StringReader(xmlFrag)))
                {
                    XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
                    nsmanager.AddNamespace("msbooks", "www.microsoft.com/books");
                    nsmanager.PushScope();
                    nsmanager.AddNamespace("msstore", "www.microsoft.com/store");

                    foreach (String prefix in nsmanager)
                    {
                        output.AppendLine("Prefix" + prefix + " Namespace=" +
                            nsmanager.LookupNamespace(prefix));
                    }
                }
                OutputTextBlock.Text = output.ToString();


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.