Bewerken

Share via


XName.Implicit(String to XName) Operator

Definition

Important

This API is not CLS-compliant.

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

public:
 static operator System::Xml::Linq::XName ^(System::String ^ expandedName);
[System.CLSCompliant(false)]
public static implicit operator System.Xml.Linq.XName (string expandedName);
[System.CLSCompliant(false)]
public static implicit operator System.Xml.Linq.XName? (string? expandedName);
[<System.CLSCompliant(false)>]
static member op_Implicit : string -> System.Xml.Linq.XName
Public Shared Widening Operator CType (expandedName As String) As XName

Parameters

expandedName
String

A string that contains an expanded XML name in the format {namespace}localname.

Returns

An XName object constructed from the expanded name.

Attributes

Examples

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

XElement el = new XElement("{http://www.adventure-works.com}Root", "content");
Console.WriteLine(el);

// 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");
Console.WriteLine(root);
Imports <xmlns="http://www.adventure-works.com">

Module Module1
    Sub Main()
        Dim el As XElement = New XElement("{http://www.adventure-works.com}Root", "content")
        Console.WriteLine(el)

        ' The preferred approach is to import a global namespace and
        ' use an XML literal.
        Dim root As XElement = <Root>content</Root>
        Console.WriteLine(root)
    End Sub
End Module

This example produces the following output:

<Root xmlns="http://www.adventure-works.com">content</Root>
<Root xmlns="http://www.adventure-works.com">content</Root>

Remarks

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

Applies to

See also