GetNamespaceOfPrefix Method

XElement.GetNamespaceOfPrefix Method

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets the namespace associated with a particular prefix for this XElement.

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

'Declaration
Public Function GetNamespaceOfPrefix ( _
	prefix As String _
) As XNamespace

Parameters

prefix
Type: System.String
A string that contains the namespace prefix to look up.

Return Value

Type: System.Xml.Linq.XNamespace
An XNamespace for the namespace associated with the prefix for this XElement.

This method looks through the XML tree for namespace attributes that are in scope for this element. Namespace prefixes are specified in namespace attributes that are in the XML tree.

The following example creates an XML tree that has a namespace with an associated prefix. It then uses this method to retrieve the XNamespace for the prefix.


'add the following line to the the Imports section:
'Imports <xmlns:aw="http://www.adventure-works.com">
Dim output As New StringBuilder
Dim xmlTree As XElement = <aw:Root/>
Dim awNamespace As XNamespace = GetXmlNamespace(aw)
output.Append(String.Format("Namespace: {0}", awNamespace))
output.Append(Environment.NewLine)

OutputTextBlock.Text = output.ToString()


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft