I’m using XmlWriter to save an XmlDocument in .Net. However all the elements that have InnerText are written with surrounding carriage return characters.
I tried using XmlWriterSettings to avoid the writing of those characters, but no luck yet.
Here it is a piece of code used:
XmlDocument outXml = new XmlDocument();
outXml.AppendChild .......
XmlWriterSettings sets = new XmlWriterSettings();
sets.Encoding = encoding;
sets.Indent = true;
XmlWriter xwriter = XmlWriter.Create(file, sets);
outXml.Save(xwriter);
xwriter.Close();
The xml output is like:
<String Id="msierrXmlFileFailedSave" Overridable="yes">
Fehler beim Speichern der Einstellungen-Datei.
</String>
The xml output needed should be like:
<String Id="msierrXmlFileFailedSave" Overridable="yes">Fehler beim Speichern der Einstellungen-Datei.</String>
Is there a way to avoid the writing of those carriage returns inside the elements?
PD: I saw an opposite question about this issue, but the solution does not apply to this case.
Thanks in advance.
Allan.c
You will want to set the XmlDocument.PreserveWhitespace property before calling Save. Another option is to use CData sections instead of inner text where the text content of the elements needs to be preserved exactly.
From the documentation: