XNamespace.Addition(XNamespace, String) XNamespace.Addition(XNamespace, String) XNamespace.Addition(XNamespace, String) XNamespace.Addition(XNamespace, String) Operator


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

 static System::Xml::Linq::XName ^ operator +(System::Xml::Linq::XNamespace ^ ns, System::String ^ localName);
public static System.Xml.Linq.XName operator + (System.Xml.Linq.XNamespace ns, string localName);
static member ( + ) : System.Xml.Linq.XNamespace * string -> System.Xml.Linq.XName
Public Shared Operator + (ns As XNamespace, localName As String) As XName


XNamespace XNamespace XNamespace XNamespace

An XNamespace that contains the namespace.

String String String String

A String that contains the local name.


The new XName constructed from the namespace and local name.


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")  
Dim aw As XNamespace = "http://www.adventure-works.com"  
Dim root As XElement = New XElement(aw + "Root", _  
    New XElement(aw + "Child") _  

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 = _  
    End Sub  
End Module  

This example produces the following output:

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


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

See also