Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

XName Implicit Conversion (String to XName)

Converts a string formatted as an expanded XML name (that is,{namespace}localname) to an XName object.

This API is not CLS-compliant. 

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

public static implicit operator XName (
	string expandedName
)

Parameters

expandedName
Type: System.String
A string that contains an expanded XML name in the format {namespace}localname.

Return Value

Type: System.Xml.Linq.XName
An XName object constructed from the expanded name.

You are using this implicit operator when you create an XElement or XAttribute by passing a string to the appropriate constructor.

The following example creates an XName by assigning a string to it, which invokes this implicit conversion operator.


StringBuilder output = new StringBuilder();
XElement el = new XElement("{http://www.adventure-works.com}Root", "content");
output.Append(el + Environment.NewLine);

// The preferred approach is to initialize an XNamespace object
// and use the overload of the addition operator.
XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root", "content");
output.Append(root + 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