1

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.

happycroc
  • 11
  • 3
  • It ouput `ExampleData` for me (by just doing `Console.WriteLine(newElement);` – Mark C. May 16 '17 at 20:17
  • My Problem is solved with: XElement newElement = new XElement("Example_Property"); XNamespace datatypes = "urn:schemas-microsoft-com:datatypes"; newElement.SetAttributeValue(XNamespace.Xmlns + "dt", datatypes.NamespaceName); newElement.Add(new XAttribute(datatypes + "dt", "string")); newElement.Value = "ExampleData"; – happycroc May 16 '17 at 20:25
  • @happycroc consider that you can answer your own question in StackOverflow – Hossein Narimani Rad May 16 '17 at 20:30

0 Answers0