XmlNamespaceManager.PopScope Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Pops a namespace scope off the stack.
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
if there are namespace scopes left on the stack; false
if there are no more namespaces to pop.
The following example adds prefix/namespace pairs to the XmlNamespaceManager and then displays all the pairs in the collection.
#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
When you call this method, all namespaces which were added to XmlNamespaceManager (by calling AddNamespace) since the last call to PopScope are removed.
Product | Versies |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET-feedback
.NET is een open source project. Selecteer een koppeling om feedback te geven: