我有一个标准的XML文档,看起来像'树'。我添加了一些节点并保存更改:
XmlDocument doc = new XmlDocument();
doc.Load(filename);
...
doc.PreserveWhitespace = true;
XmlTextWriter writer = new XmlTextWriter(filename, Encoding.Default);
doc.WriteTo(writer);
writer.Close();
然后将xml文档拉伸到一行。如何添加换行符?
答案 0 :(得分:3)
构建XmlTextWriter
之后,但在致电doc.WriteTo(writer);
之前,请插入此行:
writer.Formatting = Formatting.Indented;