Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

XmlNamespaceManager.HasNamespace Method

Gets a value indicating whether the supplied prefix has a namespace defined for the current pushed scope.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public virtual bool HasNamespace(
	string prefix
)

Parameters

prefix
Type: System.String
The prefix of the namespace you want to find.

Return Value

Type: System.Boolean
true if there is a namespace defined; otherwise, false.

To determine whether there is a default empty namespace defined, set prefix to String.Empty. If the method returns true, this indicates that there is a default namespace defined in the current scope. Returning false indicates that no default namespace is defined.

NoteNote:

xmlns:x= "" is illegal according to W3C Namespaces in XML recommendation.


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


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.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.