Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 LookupNamespace Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
XmlNamespaceManager..::.LookupNamespace Method

Gets the namespace URI for the specified prefix.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
Visual Basic (Declaration)
Public Overridable Function LookupNamespace ( _
    prefix As String _
) As String
Visual Basic (Usage)
Dim instance As XmlNamespaceManager
Dim prefix As String
Dim returnValue As String

returnValue = instance.LookupNamespace(prefix)
C#
public virtual string LookupNamespace(
    string prefix
)
Visual C++
public:
virtual String^ LookupNamespace(
    String^ prefix
)
JScript
public function LookupNamespace(
    prefix : String
) : String

Parameters

prefix
Type: System..::.String
The prefix whose namespace URI you want to resolve. To match the default namespace, pass String.Empty.

Return Value

Type: System..::.String
Returns the namespace URI for prefix or nullNothingnullptra null reference (Nothing in Visual Basic) if there is no mapped namespace. The returned string is atomized.
For more information on atomized strings, see XmlNameTable.

Implements

IXmlNamespaceResolver..::.LookupNamespace(String)

The following example adds prefix/namespace pairs to the XmlNamespaceManager and then displays all the pairs in the collection.

Visual Basic
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());
  }
}
Visual C++
#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;
}

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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker