| title | GetXmlNamespace Operator (Visual Basic) | ||
|---|---|---|---|
| ms.date | 07/20/2015 | ||
| ms.prod | .net | ||
| ms.reviewer | |||
| ms.suite | |||
| ms.technology |
|
||
| ms.topic | article | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| ms.assetid | d0d28cfd-0755-4896-ae0b-4981aa35517c | ||
| caps.latest.revision | 14 | ||
| author | dotnet-bot | ||
| ms.author | dotnetcontent |
Gets the xref:System.Xml.Linq.XNamespace object that corresponds to the specified XML namespace prefix.
GetXmlNamespace(xmlNamespacePrefix)
xmlNamespacePrefix
Optional. The string that identifies the XML namespace prefix. If supplied, this string must be a valid XML identifier. For more information, see Names of Declared XML Elements and Attributes. If no prefix is specified, the default namespace is returned. If no default namespace is specified, the empty namespace is returned.
The xref:System.Xml.Linq.XNamespace object that corresponds to the XML namespace prefix.
The GetXmlNamespace operator gets the xref:System.Xml.Linq.XNamespace object that corresponds to the XML namespace prefix xmlNamespacePrefix.
You can use XML namespace prefixes directly in XML literals and XML axis properties. However, you must use the GetXmlNamespace operator to convert a namespace prefix to an xref:System.Xml.Linq.XNamespace object before you can use it in your code. You can append an unqualified element name to an xref:System.Xml.Linq.XNamespace object to get a fully qualified xref:System.Xml.Linq.XName object, which many [!INCLUDEsqltecxlinq] methods require.
The following example imports ns as an XML namespace prefix. It then uses the prefix of the namespace to create an XML literal and access the first child node that has the qualified name ns:phone. It then passes that child node to the ShowName subroutine, which constructs a qualified name by using the GetXmlNamespace operator. The ShowName subroutine then passes the qualified name to the xref:System.Xml.Linq.XNode.Ancestors%2A method to get the parent ns:contact node.
[!code-vbVbXMLSamples#38]
When you call TestGetXmlNamespace.RunSample(), it displays a message box that contains the following text:
Name: Patrick Hines
Imports Statement (XML Namespace)
Accessing XML in Visual Basic