Formats XML code by adding line breaks and indentations to make it more human-readable.

Code (C#)

// Create new XML document
XmlDocument xmlDoc = new XmlDocument();

// Import XML code from "Input" editor

// Write XML content to StringWriter
using (StringWriter stringWriter = new StringWriter())
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
    // Configure XmlTextWriter to output formatted XML code
    xmlTextWriter.Formatting = Formatting.Indented;
    // (Optional) Set Character to use for indenting
    //xmlTextWriter.IndentChar = '\t';
    // (Optional) Set number of IndentChars to write for each level in the hierarchy 
    //xmlTextWriter.Indentation = 1;
    // Write code to "Output" editor
    Output.Text = stringWriter.ToString();
Input Type: Plain Text, Output Type: Plain Text

Download Project File

File: Format_XML_document.dvp (3.4 KB)

To open this file, DataVoila must be installed on your computer. If this is not yet the case, please click here to download the free demo version.