XML Formatter
Pretty-print and validate XML documents with proper indentation.
Formatted XML
Paste a document on the left.
About XML Formatter
XML remains the backbone of SOAP services, RSS feeds, SVG graphics and countless configuration formats. Machine-generated XML usually arrives on a single line, which hides the structure that makes it useful.
This formatter re-indents each element by nesting depth, collapses text-only elements onto one line to keep the output compact, and reports well-formedness errors with their location.
How XML Formatter works in your browser
The document is parsed with the browser’s XML parser, so malformed markup is reported with the parser’s own error rather than being silently repaired. Well-formed documents are re-indented by nesting depth, with text-only elements kept on a single line.
Comments, CDATA sections and processing instructions are preserved. Schema validation is not performed — only well-formedness.
When to use it
- Reading a single-line SOAP response or RSS feed.
- Finding the unclosed tag in a broken configuration file.
- Tidying an SVG file before committing it to a repository.
Worked examples
Inspect an element-only configuration
Settings: Format, 2 spaces
Input
<root><item id="1">A</item><item id="2"/></root>Expected output
<root>
<item id="1">A</item>
<item id="2"/>
</root>Element-only structure is indented while a text-bearing element stays on one line. Minify removes indentation line breaks between these elements, without shortening attribute or element names.
Preserve meaningful text spacing
Settings: Format or Minify
Input
<p>Hello <b>world</b> today</p>Expected output
<p>Hello <b>world</b> today</p>Mixed content remains unchanged. Replacing its spaces or adding newlines could change rendered text. CDATA, quoted attribute values, inline spacing and xml:space="preserve" subtrees are retained.
Limits and checks before you use the result
- Validation checks XML well-formedness, not an XSD schema, a SOAP contract or RSS compatibility. A document can parse successfully while being invalid for its intended application.
- Documents containing a DOCTYPE are returned unchanged with a warning. This tool does not rewrite DTD declarations or resolve external schemas.
- Indentation changes whitespace nodes in element-only content. Do not use it as XML canonicalization or to prepare digitally signed XML; retain the original and compare results in the target application.
Frequently asked questions
Is the document validated?
Yes, it is parsed with the browser XML parser, so malformed markup is reported with the parser own error message.
Are comments and CDATA preserved?
Yes. Comments, CDATA and processing instructions retain their source text. Mixed content and xml:space="preserve" subtrees stay unchanged. Documents with a DOCTYPE are returned unchanged with a warning.
Does it validate against a schema?
No. Only well-formedness is checked; schema validation is out of scope for a browser tool.