Create a gist now

Instantly share code, notes, and snippets.

Example of pretty-printing XML in C# using the XmlWriter class
using System;
using System.Text;
using System.Xml;
using System.Xml.Linq;
static string PrettyXml(string xml)
var stringBuilder = new StringBuilder();
var element = XElement.Parse(xml);
var settings = new XmlWriterSettings();
settings.OmitXmlDeclaration = true;
settings.Indent = true;
settings.NewLineOnAttributes = true;
using (var xmlWriter = XmlWriter.Create(stringBuilder, settings))
return stringBuilder.ToString();

This comment has been minimized.

Show comment
Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment