Freigeben über


XmlNamespaceManager Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Inheritance Hierarchy

System.Object
  System.Xml.XmlNamespaceManager
    System.Xml.Xsl.XsltContext

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public Class XmlNamespaceManager _
    Implements IXmlNamespaceResolver, IEnumerable
public class XmlNamespaceManager : IXmlNamespaceResolver, 
    IEnumerable

The XmlNamespaceManager type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlNamespaceManager Initializes a new instance of the XmlNamespaceManager class with the specified XmlNameTable.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 DefaultNamespace Gets the namespace URI for the default namespace.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 NameTable Gets the XmlNameTable associated with this object.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 AddNamespace Adds the given namespace to the collection.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetEnumerator Returns an enumerator to use to iterate through the namespaces in the XmlNamespaceManager.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetNamespacesInScope Gets a collection of namespace names keyed by prefix which can be used to enumerate the namespaces currently in scope.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 HasNamespace Gets a value indicating whether the supplied prefix has a namespace defined for the current pushed scope.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 LookupNamespace Gets the namespace URI for the specified prefix.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 LookupPrefix Finds the prefix declared for the given namespace URI.
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 PopScope Pops a namespace scope off the stack.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 PushScope Pushes a namespace scope onto the stack.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 RemoveNamespace Removes the given namespace for the given prefix.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Extension Methods

  Name Description
Public Extension MethodSupported by Silverlight for Windows Phone AsQueryable Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension MethodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Cast<TResult> Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension MethodSupported by Silverlight for Windows PhoneSupported by Xbox 360 OfType<TResult> Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)

Top

Remarks

XmlNamespaceManager stores prefixes and namespaces as strings.

Examples

Dim output As New StringBuilder()

Dim xmlFrag As String = _
      "<root>" & _
        "<data>" & _
         "<items>" & _
          "<item id='1'>" & _
          "</item>" & _
         "</items>" & _
        "</data>" & _
        "</root>"

Using reader As XmlReader = XmlReader.Create(New StringReader(xmlFrag))
    Dim nsmanager As New XmlNamespaceManager(reader.NameTable)
    nsmanager.AddNamespace("msbooks", "www.microsoft.com/books")
    nsmanager.PushScope()
    nsmanager.AddNamespace("msstore", "www.microsoft.com/store")

    Dim prefix As String
    For Each prefix In nsmanager
        output.AppendLine(("Prefix" + prefix + _
                           " Namespace=" + nsmanager.LookupNamespace(prefix)))
    Next prefix
End Using
OutputTextBlock.Text = output.ToString()

                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();

Version Information

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

Platforms

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

Thread Safety

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