Skip to content

Instantly share code, notes, and snippets.

@yetanotherchris
Created November 8, 2011 01:11
Show Gist options
  • Save yetanotherchris/1346732 to your computer and use it in GitHub Desktop.
Save yetanotherchris/1346732 to your computer and use it in GitHub Desktop.
format xml
///
/// Formats the provided XML so it's indented and humanly-readable.
///
/// <param name="inputXml" />The input XML to format.
///
public static string FormatXml(string inputXml)
{
XmlDocument document = new XmlDocument();
document.Load(new StringReader(inputXml));
StringBuilder builder = new StringBuilder();
using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(builder)))
{
writer.Formatting = Formatting.Indented;
document.Save(writer);
}
return builder.ToString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment