How to add XNamespace (Xml.Linq) to XElement?

51 views Asked by At

Hi i need to create some XML Elements like:

<Example_Property xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="string">ExampleData</Example_Property>

But my code:

            XElement newElement = new XElement("Example_Property");

            XNamespace datatypes = "urn:schemas-microsoft-com:datatypes";

            newElement.Add(new XAttribute(datatypes + "dt", "string"));

            newElement.Value = "ExampleData";

only creates so far:

<Example_Property dt:dt="string">ExampleData</Example_Property>

How i have to work with the Namespace?

Thanks in advance.

0

There are 0 answers