XmlNamespaceManager::HasNamespace Method (String^)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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)

virtual bool HasNamespace(
	String^ 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. A return value of true indicates that there is a default namespace defined in the current scope; false indicates that no default namespace is defined.


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

The following example displays the default namespace, if one exists.

if ( nsmgr->HasNamespace( String::Empty ) )
   Console::WriteLine( nsmgr->DefaultNamespace );

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