How to Display Formatted XML
If, by "formatting", you mean indented then you can load it into XmlDocument and write it into an XmlWriter initialized with an XmlWriterSettings that has Indent set to true
.
private string FormatXml(string input){ XmlDocument doc = new XmlDocument(); doc.LoadXml(input); using (StringWriter buffer = new StringWriter()) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlWriter.Create(buffer, settings)) { doc.WriteTo( writer ); writer.Flush(); } buffer.Flush(); return buffer.ToString(); }}