Thursday, 14 April 2016

XML : Create xml-attribute with namespace programatically

How can I create the following as XElement?

  <data name="MyKey" xml:space="preserve">      <value>Date of birth</value>      <comment>Some comment</comment>  </data>    

It throws

"The ':' character, hexadecimal value 0x3A, cannot be included in a name."

  var data = new XElement("data");    data.Add(new XAttribute("name", translation.Key));  data.Add(new XAttribute("xml:space", "preserve")); // <-- here is the error    data.Add(new XElement("value") { Value = "Date of birth" });  data.Add(new XElement("comment") { Value = "Some comment" });    

As this is part of a ResX-file, there will be many such <data></data>-elements.

No comments:

Post a Comment