This documentation is archived and is not being maintained.

XmlNamespaceManager.PopScope Method

Pops a namespace scope off the stack.

[Visual Basic]
Public Overridable Function PopScope() As Boolean
[C#]
public virtual bool PopScope();
[C++]
public: virtual bool PopScope();
[JScript]
public function PopScope() : Boolean;

Return Value

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

Remarks

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

Example

[Visual Basic, C#, C++] The following example adds prefix/namespace pairs to the XmlNamespaceManager and then displays all the pairs in the collection.

[Visual Basic] 
Option Explicit
Option Strict

Imports System
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim test As New Sample()
    End Sub 'Main
    
    Public Sub New()
        ' Create the XmlNamespaceManager.
        Dim nt As New NameTable()
        Dim nsmgr As 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...")
        ShowAllNamespaces(nsmgr)
    End Sub 'New
    
    
    Private Sub ShowAllNamespaces(nsmgr As XmlNamespaceManager)
        Do
            Dim prefix As String
            For Each prefix In  nsmgr
                Console.WriteLine("Prefix={0}, Namespace={1}", prefix, nsmgr.LookupNamespace(prefix))
            Next prefix
        Loop While nsmgr.PopScope()
    End Sub 'ShowAllNamespaces
End Class 'Sample

[C#] 
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...");
    ShowAllNamespaces(nsmgr);
  }

  private void ShowAllNamespaces(XmlNamespaceManager nsmgr)
  {
    do{
       foreach (String prefix in nsmgr)
       {
        Console.WriteLine("Prefix={0}, Namespace={1}", prefix,nsmgr.LookupNamespace(prefix));
       } 
    }
    while (nsmgr.PopScope());
  }
}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;

public __gc class Sample
{
public:
  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...");
    ShowAllNamespaces(nsmgr);
  }

private:
  void ShowAllNamespaces(XmlNamespaceManager* nsmgr)
  {
    do{
       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();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

XmlNamespaceManager Class | XmlNamespaceManager Members | System.Xml Namespace

Show: