根据其他答案,我研究
XmlTextWriter并提出了以下帮助方法:
static public string Beautify(this Xmldocument doc){ StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings { Indent = true, IndentChars = " ", newlineChars = "rn", newlineHandling = newlineHandling.Replace }; using (XmlWriter writer = XmlWriter.Create(sb, settings)) { doc.Save(writer); } return sb.ToString();}
它比我期望的要多一些代码,但它的工作方式只是桃花心木。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)