Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

XmlNamespaceManager.PushScope Method

Definition

Namespace:
System.Xml
Assemblies:
System.Xml.dll, System.Xml.ReaderWriter.dll
Assemblies:
netstandard.dll, System.Xml.ReaderWriter.dll
Assembly:
System.Xml.ReaderWriter.dll
Assembly:
System.Xml.dll
Assembly:
netstandard.dll
Source:
XmlNamespacemanager.cs
Source:
XmlNamespacemanager.cs
Source:
XmlNamespacemanager.cs
Source:
XmlNamespacemanager.cs
Source:
XmlNamespacemanager.cs

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.

Pushes a namespace scope onto the stack.

public:
 virtual void PushScope();
public virtual void PushScope();
abstract member PushScope : unit -> unit
override this.PushScope : unit -> unit
Public Overridable Sub PushScope ()

Examples

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

Remarks

After a call to this method, all namespaces, which are added to XmlNamespaceManager (by calling AddNamespace), belong to the pushed namespace scope.

Applies to

See also


Feedback

Was this page helpful?