Поделиться через


XmlNamespaceManager.PushScope Method

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

Pushes a namespace scope onto the stack.

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

Syntax

'Declaration
Public Overridable Sub PushScope
public virtual void PushScope()

Remarks

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

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.