XNamespace.Addition(XNamespace, String) Operator
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Combines an XNamespace object with a local name to create an XName.
public:
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
Parameters
- ns
- XNamespace
An XNamespace that contains the namespace.
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);
Dim aw As XNamespace = "http://www.adventure-works.com"
Dim root As XElement = 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.