XmlNamespaceManager.PopScope 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將命名空間範圍自堆疊取出。
public:
virtual bool PopScope();
public virtual bool PopScope ();
abstract member PopScope : unit -> bool
override this.PopScope : unit -> bool
Public Overridable Function PopScope () As Boolean
傳回
如果堆疊上留有命名空間範圍,則為 true
,若未取出其他命名空間,則為 false
。
範例
下列範例會將前置詞/命名空間組新增至 , XmlNamespaceManager 然後顯示集合中的所有配對。
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
public ref class Sample
{
public:
Sample()
{
// Create the XmlNamespaceManager.
NameTable^ nt = gcnew NameTable;
XmlNamespaceManager^ nsmgr = gcnew 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
{
System::Collections::IEnumerator^ myEnum = nsmgr->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ prefix = safe_cast<String^>(myEnum->Current);
Console::WriteLine( "Prefix={0}, Namespace={1}", prefix, nsmgr->LookupNamespace( prefix ) );
}
}
while ( nsmgr->PopScope() );
}
};
int main()
{
gcnew Sample;
}
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());
}
}
Option Explicit
Option Strict
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim test As New Sample()
End Sub
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
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
End Class
備註
當您呼叫此方法時,自上次) 呼叫 AddNamespacePopScope 之後呼叫 之後,所有新增至 XmlNamespaceManager (的命名空間都會被移除。