XML Formatter
Pretty-print XML with consistent 2-space indentation. Validates as it formats. Browser-only.
0 characters
0 characters
About XML Formatter
The XML formatter takes an XML document — minified, hand-edited, or in any other shape — and re-emits it with one element per line and consistent indentation. Parsing is done with the browser's native DOMParser so the document is also validated for well-formedness; any structural error is reported with the offending location.
When to use it
- Reading a minified RSS or sitemap feed
- Reviewing SOAP envelopes or other XML payloads from an API trace
- Cleaning up hand-authored XML before checking it into source control
- Preparing XML for a bug report or documentation
- Diffing two XML files after normalizing both
How it works
The input is parsed into a DOM tree by the browser. The formatter then walks the tree, emitting each element on its own line with two-space indentation per nesting level. Text nodes are trimmed; pure-whitespace text is dropped. Element attributes are kept inline on the opening tag.
Examples
Minified → indented
<root><a id="1"><b>hello</b></a></root>
<root>
<a id="1">
<b>hello</b>
</a>
</root>Frequently asked questions
- Is my XML uploaded anywhere?
- No. Parsing and formatting use the browser's built-in DOMParser. Your XML never leaves your device.
- What about CDATA and comments?
- Comments and CDATA sections are dropped in the current implementation, which is a known limitation. If preserving them matters, use a dedicated XML editor.
- Does it validate against a schema?
- No — only well-formedness is checked. To validate against a DTD, XSD, or RelaxNG schema, use a dedicated validator.
- Can it handle large documents?
- DOMParser loads the entire document into memory. Documents up to tens of megabytes generally work; for gigabyte-sized XML use a streaming parser at the command line.