Freigeben über


XmlNamespaceManager.LookupPrefix Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Finds the prefix declared for the given namespace URI.

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

Syntax

'Declaration
Public Overridable Function LookupPrefix ( _
    uri As String _
) As String
public virtual string LookupPrefix(
    string uri
)

Parameters

  • uri
    Type: System.String
    The namespace to resolve for the prefix.

Return Value

Type: System.String
The matching prefix. If there is no mapped prefix, the method returns String.Empty. If a null value is supplied, then nulla null reference (Nothing in Visual Basic) is returned.

Implements

IXmlNamespaceResolver.LookupPrefix(String)

Remarks

This method finds the mapped prefix by walking the stack (that is, it looks globally). The supplied string must be atomized for the lookup to succeed. In other words, the supplied string object must exist in the XmlNamespaceManager's NameTable.

The returned string is also atomized. For more information on atomized strings, see XmlNameTable.

Examples

Dim output As New StringBuilder()
' 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")

Dim prefix As String = nsmgr.LookupPrefix("www.wideworldimporters.com/europe")
output.AppendLine((" Before removing prefix: " + prefix))
nsmgr.RemoveNamespace(prefix, "www.wideworldimporters.com/europe")
output.Append((" Before removing prefix: " + nsmgr.LookupPrefix("www.wideworldimporters.com/europe")))

OutputTextBlock.Text = output.ToString()
StringBuilder output = new StringBuilder();
// 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");

String prefix = nsmgr.LookupPrefix("www.wideworldimporters.com/europe");
output.AppendLine(" Before removing prefix: " + prefix);
nsmgr.RemoveNamespace(prefix, "www.wideworldimporters.com/europe");
output.Append(" Before removing prefix: " + nsmgr.LookupPrefix("www.wideworldimporters.com/europe"));

OutputTextBlock.Text = output.ToString();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.