Skip to content

Instantly share code, notes, and snippets.

@Nilzor
Created January 19, 2012 16:13
Show Gist options
  • Save Nilzor/1640865 to your computer and use it in GitHub Desktop.
Save Nilzor/1640865 to your computer and use it in GitHub Desktop.
String to String XML pretty Printer in C#
public string PrettyPrint(string xml)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
var sb = new StringBuilder();
var sw = new StringWriter(sb);
var xw = new XmlTextWriter(sw);
xw.Formatting = Formatting.Indented;
doc.WriteTo(xw);
return sb.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment