.net: XmlDocument creates one line xml document
I have a standard XML document, which looks like a 'tree'. I add some nodes and save changes:
XmlDocument doc = new XmlDocument();
doc.Load(filename);
...
doc.PreserveWhitespace = true;
XmlText开发者_运维问答Writer writer = new XmlTextWriter(filename, Encoding.Default);
doc.WriteTo(writer);
writer.Close();
and after that xml document stretch into one line. How to add line feeds?
After you construct the XmlTextWriter
, but before you call doc.WriteTo(writer);
, insert this line:
writer.Formatting = Formatting.Indented;
精彩评论