XML Formatter
Pretty-print and indent XML so it's easy to read and debug.
Was this tool helpful?
Thanks for the feedback!
Paste compact or messy XML and this XML formatter puts every tag on its own line, indented two spaces per nesting level, so the structure of a feed, sitemap, SOAP response or configuration file becomes easy to follow. It works in your browser and formats even markup that is not well-formed, which makes it a reading aid rather than a validator.
What happens to your XML
- Whitespace between tags is removed.
- The text is split into tags and text runs, and each one goes on its own line.
- An opening tag increases the indent for what follows; a closing tag steps back one level.
- Self-closing tags such as
<empty/>, the<?xml ?>declaration and comments sit on their own lines without changing the depth.
Example
The input <root><item>A</item><item>B</item></root> becomes:
<root>
<item>
A
</item>
<item>
B
</item>
</root>
Notice that text content moves onto its own line. A book record such as <title>Godaan</title> therefore takes three lines, with Godaan indented one level deeper than its tags.
Use the output for reading, keep the original for processing
Because text is placed on separate lines, the formatted file contains extra line breaks and spaces inside elements. Most data parsers that trim text will not care, but whitespace is meaningful in some documents:
- elements marked
xml:space="preserve"; - mixed content, where text and inline tags interleave, as in XHTML or the
document.xmlinside a DOCX file; - digitally signed XML such as SAML assertions and signed e-invoices, where any whitespace change invalidates the signature.
Read and debug with the formatted copy, but send or store the untouched original.
It formats, it does not validate
Broken markup is still indented, just unevenly. For <a><b>x</a> the closing </a> ends up aligned under <b>, one level too deep, and that misalignment is often the quickest clue to a missing closing tag. Attribute values or CDATA sections that contain angle brackets can also be split in odd places. To confirm a file is well-formed, open it in Chrome or Firefox, which report the line and column of the first parsing error.
Where it helps
Common jobs include checking a sitemap.xml before submitting it to search engines (the XML Sitemap Generator builds one from scratch), reading an RSS or Atom feed, inspecting a SOAP API response, reviewing Android layout files and looking through accounting data exported as XML from software such as Tally. When a JavaScript application needs the same data, the XML to JSON Converter does the conversion.