使用XmlDocument类:http://msdn.microsoft.com/en-us/library/system.xml.xmldocument(VS.85).aspx
如何在调用Save()之前整理XML文本以使其缩进并正确放置在新行上?
答案 0 :(得分:1)
使用带有XmlWriter的Save()重载并使用XmlWriterSettings实例配置XmlWriter。例如
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = " ";
settings.NewLineOnAttributes = true;
//Using XmlWriter to create xml file.
using (XmlWriter writer = XmlWriter.Create("some-file.xml",settings))
{
doc.Save(writer)
}