Export (0) Print
Expand All

XElement.GetNamespaceOfPrefix Method

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

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

public XNamespace GetNamespaceOfPrefix(
	string prefix
)

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.


StringBuilder output = new StringBuilder();
XElement xmlTree = XElement.Parse("<Root xmlns:aw='http://www.adventure-works.com'/>");
XNamespace awNamespace = xmlTree.GetNamespaceOfPrefix("aw");
output.Append("Namespace: " + awNamespace + Environment.NewLine);

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:
© 2015 Microsoft