XNamespace::Addition Operator (XNamespace^, String^)
Combines an XNamespace object with a local name to create an XName.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
Parameters
- ns
-
Type:
System.Xml.Linq::XNamespace^
An XNamespace that contains the namespace.
- localName
-
Type:
System::String^
A String that contains the local name.
Return Value
Type: System.Xml.Linq::XName^The new XName constructed from the namespace and local name.
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.
The following example shows the use of the + operator to create an XName from an XNamespace and a local name.
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>
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1