When working with xml files in C #, it was necessary to create the following element via linq2xml:


However, when trying to add it programmatically

 new XAttribute("xml:space", "preserve") 

I get this error:

The "character": "hexadecimal value 0x3A cannot be used in names."

How can I add a string of type "x: y"?

Slightly more complete code:

 xdoc.Element("root").Add(new XElement("data", new XAttribute("name", x.Key), new XAttribute("xmlspace", "preserve"),new XElement("value", x.Value))); // Надо xml:space 

If anyone asks the question, "WTF is that?", The answer is that this is a software addition of Visual Studio localization resources. (Initially taken via linq2xml from the Java resource file to Dictionary and then converted into the Visual Studio resource file), and yes, I know a lot about perversions.

  • I suspect that you need to poke around in the direction of the namespace - Chad

1 answer 1

And if so:

 XmlDocument.CreateElement("prefix", "name", "uri"); //для элементов new XAttribute(XNamespace.Xml + "space", "preserve"); //для атрибутов 
  • For sure. Thank. - Olter