Fixing xml formatting

This commit is contained in:
Chris Cameron
2017-10-12 11:53:13 -04:00
parent f7842116a4
commit a499a97cf6

View File

@@ -1015,23 +1015,19 @@ namespace ICD.Common.Utils.Xml
[PublicAPI] [PublicAPI]
public static string Format(string xml) public static string Format(string xml)
{ {
using (IcdMemoryStream mStream = new IcdMemoryStream()) StringBuilder builder = new StringBuilder();
using (IcdStringWriter stringWriter = new IcdStringWriter(builder))
{ {
using (IcdXmlTextWriter writer = new IcdXmlTextWriter(mStream, Encoding.UTF8)) using (IcdXmlTextWriter writer = new IcdXmlTextWriter(stringWriter))
{ {
IcdXmlDocument document = new IcdXmlDocument(); IcdXmlDocument document = new IcdXmlDocument();
// Load the XmlDocument with the XML.
document.LoadXml(xml); document.LoadXml(xml);
// Write the XML into a formatting IcdXmlTextWriter
document.WriteContentTo(writer); document.WriteContentTo(writer);
writer.Flush();
mStream.Flush();
// Have to rewind the MemoryStream in order to read its contents. writer.Flush();
mStream.Position = 0;
return new IcdStreamReader(mStream).ReadToEnd(); return builder.ToString();
} }
} }
} }