Поделиться через


XNamespace.Addition Operator

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

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

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

Syntax

'Declaration
Public Shared Operator + ( _
    ns As XNamespace, _
    localName As String _
) As XName
public static XName operator +(
    XNamespace ns,
    string localName
)

Parameters

Return Value

Type: System.Xml.Linq.XName
The new XName constructed from the namespace and local name.

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.

Examples

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

Dim output As New StringBuilder
Dim aw As XNamespace = "https://www.adventure-works.com"
Dim root As XElement = New XElement(aw + "Root", _
    New XElement(aw + "Child") _
)
output.Append(root)
output.Append(Environment.NewLine)

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