次の方法で共有


XmlNamespaceManager.PopScope メソッド

名前空間スコープをスタックからポップします。

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

戻り値

スタックに名前空間スコープが残されている場合は true 。ポップする名前空間がそれ以上ない場合は false

解説

このメソッドを呼び出すと、 AddNamespace を呼び出すことによって最後の PopScope の呼び出し以降 XmlNamespaceManager に追加されたすべての名前空間が削除されます。

使用例

[Visual Basic, C#, C++] プリフィックスと名前空間のペアを XmlNamespaceManager に追加してから、コレクション内のすべてのペアを表示する例を次に示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

XmlNamespaceManager クラス | XmlNamespaceManager メンバ | System.Xml 名前空間