Quick guide
How to use the XML Formatter
- Enter or choose xml, action, indentation.
- Select Process XML.
- Review the main result, supporting breakdown, and step-by-step calculation notes.
- Copy the output or download the generated file when available.
What this tool does
Validate, pretty-print, or minify XML documents directly in your browser using native XML parsing and serialization. Unlike naive regex formatters that corrupt entities or break mixed-content whitespace, this engine preserves XML declarations, comments, entity escapes (&, <), xml:space="preserve" blocks, and stops cleanly on the first syntax error.
Calculation method
- Parse the input strictly with DOMParser("application/xml") and halt immediately with the parser’s error description if the XML is not well-formed.
- Preserve XML declarations, processing instructions, comments, attribute escaping, CDATA sections, and mixed-content text nodes.
- Apply 2-space, 4-space, or tab indentation in Format mode—or strip only insignificant element-only indentation in Minify mode—and prepare a UTF-8 XML download.
Good to know: XML is parsed and transformed only in this browser tab.
Example: formatting XML while preserving escaped entities
Input: <catalog><item id="1"><title>Tom & Jerry <3</title></item></catalog>
Result: Indented multi-line XML retaining & and < intact, plus local formatted.xml download
Proper XML serialization keeps special characters escaped so the formatted output stays 100% valid XML when re-parsed by downstream tools.
The 5 predefined XML character entities
| Character | Required XML Entity | Where Needed |
|---|---|---|
| & | & | Always in text and attribute values |
| < | < | Always in text and attribute values |
| > | > | Recommended in text (required in ]]> ) |
| " | " | Inside double-quoted attribute values |
| ' | ' | Inside single-quoted attribute values |
Practical uses
- Formatting unreadable minified SOAP or REST XML payloads
- Validating RSS feeds, sitemaps, and SVG markup
- Minifying Android/Maven/config XML without breaking text nodes
- Inspecting private XML configs locally without cloud uploads
Accuracy tips and common mistakes
- Unescaped ampersands (such as “A & B” instead of “A & B”) are the #1 cause of XML syntax errors.
- Add xml:space="preserve" on elements whose leading/trailing spaces are semantically significant—both Format and Minify modes respect it.
- Downloads are normalized to UTF-8 encoding so modern editors open them consistently.