Here is simple c# extension method to format your XML data. This is useful for logging xml data to trace files, etc:
1 2 3 4 5 6 7 8 9 10 |
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(); } } |