I am writing a wrapper for Braindead's XML API. I have an XDocument that I need to turn into a string. Because their XML parser is so sophisticated that it cannot even handle spaces between XML nodes, the document declaration MUST BE EXACT:
<?xml version="1.0"?>
However, the XDocument.Save () method always adds an encoding attribute to this declaration:
<?xml version="1.0" encoding="utf-16"?>
With the last hour spent on Google and Stack looking for a better way to generate an XML string, I can do this:
string result = xmlStringBuilder.ToString().Replace(@"encoding=""utf-16"", string.Empty));
I tried
xdoc.Declaration = new XDeclaration("1.0", null, null);
XDocument , ; , Save(), , , ( TextWriter, XmlWriterSettings ..).
- , ?