Move Beautify to helper

This commit is contained in:
Matt Nadareski
2016-04-06 00:43:02 -07:00
parent 81cfbb0640
commit f212603619
3 changed files with 28 additions and 46 deletions

View File

@@ -115,33 +115,12 @@ namespace SabreTools
tempDoc.AppendChild(tempDoc.CreateDocumentType("datafile", "-//Logiqx//DTD ROM Management Datafile//EN", "http://www.logiqx.com/Dats/datafile.dtd", null));
tempDoc.AppendChild(outNode);
string outPath = Path.GetFileNameWithoutExtension(filename) + ".new" + Path.GetExtension(filename);
File.WriteAllText(outPath, Beautify(tempDoc));
File.WriteAllText(outPath, Style.Beautify(tempDoc));
}
private static void Help()
{
}
// http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument
// http://www.timvw.be/2007/01/08/generating-utf-8-with-systemxmlxmlwriter/
static public string Beautify(XmlDocument doc)
{
MemoryStream ms = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings
{
Encoding = new UTF8Encoding(false),
Indent = true,
IndentChars = "\t",
NewLineChars = "\r\n",
NewLineHandling = NewLineHandling.Replace
};
using (XmlWriter writer = XmlWriter.Create(ms, settings))
{
doc.Save(writer);
}
return Encoding.UTF8.GetString(ms.ToArray());
}
}
}