Here is simple c# extension method to format your XML data. This is useful for logging xml data to trace files, etc:
public static class XmlDocumentPrettyExtension
{
public static string Prettyify(this XmlDocument xmlDocument)
{
var stringWriter = new StringWriter(new StringBuilder());
var xmlTextWriter = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented };
xmlDocument.Save(xmlTextWriter);
return stringWriter.ToString();
}
}
Comments