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 ()
public boolean PopScope ()
public function PopScope () : boolean
Not applicable.

Return Value

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...");
    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());
  }
}

import System.*;
import System.IO.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        Sample test = new Sample();
    } //main

    public Sample()
    {
        // Create the XmlNamespaceManager.
        NameTable nT = new NameTable();
        XmlNamespaceManager nsMgr = new XmlNamespaceManager(nT);

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

        //Adds another default namespace.
        nsMgr.AddNamespace("", "www.lucernepublishing.com"); 
        nsMgr.AddNamespace("partners", "www.lucernepublishing.com/partners");
        Console.WriteLine("Show all the prefix/namespace pairs in the " 
            + "XmlNamespaceManager...");
        ShowAllNamespaces(nsMgr);
    } //Sample

    private void ShowAllNamespaces(XmlNamespaceManager nsMgr)
    {
        do {
            String prefix;
            System.Collections.IEnumerator objEnum = nsMgr.GetEnumerator();
            while (objEnum.MoveNext()) {
                prefix = objEnum.get_Current().ToString();
                Console.WriteLine("Prefix={0}, Namespace={1}", prefix, 
                    nsMgr.LookupNamespace(prefix));
            }
        } while (nsMgr.PopScope());
    } //ShowAllNamespaces
} //Sample

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft