Export (0) Print
Expand All

XmlNamespaceManager.PopScope Method

Pops a namespace scope off the stack.

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

public virtual bool PopScope()

Return Value

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

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

The following example adds prefix/namespace pairs to the XmlNamespaceManager and then displays all the pairs in the collection.

using System;
using System.IO;
using System.Xml;

public class Sample
  public static void Main()
    Sample test = new Sample();
  public Sample()
    // Create the XmlNamespaceManager.
    NameTable nt = new NameTable();
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);

    // Add prefix/namespace pairs to the XmlNamespaceManager.
    nsmgr.AddNamespace("", "www.wideworldimporters.com"); //Adds a default namespace.
    nsmgr.AddNamespace("europe", "www.wideworldimporters.com/europe");
    nsmgr.PushScope();  //Pushes a namespace scope on the stack.
    nsmgr.AddNamespace("", "www.lucernepublishing.com"); //Adds another default namespace.
    nsmgr.AddNamespace("partners", "www.lucernepublishing.com/partners");

    Console.WriteLine("Show all the prefix/namespace pairs in the XmlNamespaceManager...");

  private void ShowAllNamespaces(XmlNamespaceManager nsmgr)
       foreach (String prefix in nsmgr)
        Console.WriteLine("Prefix={0}, Namespace={1}", prefix,nsmgr.LookupNamespace(prefix));
    while (nsmgr.PopScope());
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

public __gc class Sample
    // Create the XmlNamespaceManager.
    NameTable* nt = new NameTable();
    XmlNamespaceManager* nsmgr = new XmlNamespaceManager(nt);

    // Add prefix/namespace pairs to the XmlNamespaceManager.
    nsmgr->AddNamespace(S"", S"www.wideworldimporters.com"); //Adds a default namespace.
    nsmgr->AddNamespace(S"europe", S"www.wideworldimporters.com/europe");
    nsmgr->PushScope();  //Pushes a namespace scope on the stack.
    nsmgr->AddNamespace(S"", S"www.lucernepublishing.com"); //Adds another default namespace.
    nsmgr->AddNamespace(S"partners", S"www.lucernepublishing.com/partners");

    Console::WriteLine(S"Show all the prefix/namespace pairs in the XmlNamespaceManager...");

  void ShowAllNamespaces(XmlNamespaceManager* nsmgr)
       System::Collections::IEnumerator* myEnum = nsmgr->GetEnumerator();
       while (myEnum->MoveNext())
           String* prefix = __try_cast<String*>(myEnum->Current);
        Console::WriteLine(S"Prefix={0}, Namespace={1}",prefix,nsmgr->LookupNamespace(prefix));
    while (nsmgr->PopScope());

int main()
  new Sample();

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

© 2015 Microsoft