XName Implicit Conversion (String to XName)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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)

Syntax

'Declaration
Public Shared Widening Operator CType ( _
    expandedName As String _
) As XName
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.

Remarks

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

Examples

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

'add the following line to the the Imports section:
'Imports <xmlns="https://www.adventure-works.com">
Dim output As New StringBuilder
Dim el As XElement = New XElement("{https://www.adventure-works.com}Root", "content")
output.Append(el)
output.Append(Environment.NewLine)

' The preferred approach is to import a global namespace and 
' use an XML literal.
Dim root As XElement = <Root>content</Root>
output.Append(root)
output.Append(Environment.NewLine)

OutputTextBlock.Text = output.ToString()
StringBuilder output = new StringBuilder();
XElement el = new XElement("{https://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 = "https://www.adventure-works.com";
XElement root = new XElement(aw + "Root", "content");
output.Append(root + Environment.NewLine);

OutputTextBlock.Text = output.ToString();

Version Information

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

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.