XmlNamespaceManager.LookupNamespace Method (String)


Gets the namespace URI for the specified prefix.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public virtual string LookupNamespace(
	string 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 null if there is no mapped namespace. The returned string is atomized.

For more information on atomized strings, see the XmlNameTable class.

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...");

  private void ShowAllNamespaces(XmlNamespaceManager nsmgr)
       foreach (String prefix in nsmgr)
        Console.WriteLine("Prefix={0}, Namespace={1}", prefix,nsmgr.LookupNamespace(prefix));
    while (nsmgr.PopScope());

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top