Export (0) Print
Expand All

XmlNamespaceManager.LookupNamespace Method

Gets the namespace URI for the specified prefix.

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

public virtual string LookupNamespace(
	string prefix
)

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 null if there is no mapped namespace. The returned string is atomized.
For more information on atomized strings, see XmlNameTable.

Implements

IXmlNamespaceResolver.LookupNamespace(String)



                StringBuilder output = new StringBuilder();

                // Create the string containing the XML to read.
                String xmlFrag =
                    @"<root>
                        <data>
	                        <items>
		                        <item id='1'>
		                        </item>
	                        </items>
                        </data>
                        </root>";

                using (XmlReader reader = XmlReader.Create(new StringReader(xmlFrag)))
                {
                    XmlNamespaceManager nsmanager = new XmlNamespaceManager(reader.NameTable);
                    nsmanager.AddNamespace("msbooks", "www.microsoft.com/books");
                    nsmanager.PushScope();
                    nsmanager.AddNamespace("msstore", "www.microsoft.com/store");

                    foreach (String prefix in nsmanager)
                    {
                        output.AppendLine("Prefix" + prefix + " Namespace=" +
                            nsmanager.LookupNamespace(prefix));
                    }
                }
                OutputTextBlock.Text = output.ToString();


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

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

Community Additions

ADD
Show:
© 2014 Microsoft