اقرأ باللغة الإنجليزية تحرير

مشاركة عبر


XNamespace.Addition(XNamespace, String) Operator

Definition

Combines an XNamespace object with a local name to create an XName.

public static System.Xml.Linq.XName operator +(System.Xml.Linq.XNamespace ns, string localName);

Parameters

ns
XNamespace

An XNamespace that contains the namespace.

localName
String

A String that contains the local name.

Returns

The new XName constructed from the namespace and local name.

Examples

The following example shows the use of the + operator to create an XName from an XNamespace and a local name.

XNamespace aw = "http://www.adventure-works.com";
XElement root = new XElement(aw + "Root",
    new XElement(aw + "Child")
);
Console.WriteLine(root);

In Visual Basic, this is the preferred idiom:

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

Module Module1
    Sub Main()
        Dim aw As XNamespace = GetXmlNamespace()
        Dim root As XElement = _
            <Root>
                <Child/>
            </Root>
        Console.WriteLine(root)
    End Sub
End Module

This example produces the following output:

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

Remarks

This operator enables the common idiom of combining a namespace and a local name in the construction of an element or attribute. This idiom provides some of the benefits of having namespace prefixes, in that you can refer to a namespace using a variable that is short. This eliminates syntactic noise in the code that creates XML trees.

Applies to

منتج الإصدارات
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also