- Home
- XML Formatter
XML Formatter
Format, minify, and validate XML with namespace, comment, CDATA, and mixed-content preservation — entirely in your browser.
Paste XML or load the example. Parsing and formatting stay in this browser.
Parser detail:
Output copied to your clipboard.
Copy failed — select the output and copy it manually.
Processed locally
Your XML never leaves this browser. Nothing is uploaded, stored, or sent to analytics.
How it works
Paste XML into the editor, choose 2- or 4-space indentation, then select Format XML. Minify removes formatting whitespace, and Validate reports whether the document is well-formed without producing output.
The output area is read-only and is cleared when the input changes, so it always reflects the current document. Copy output copies exactly what is shown.
What is preserved
Namespaces and namespace declarations, attributes and their values, comments, CDATA sections, processing instructions, the XML declaration, and the DOCTYPE are preserved. Empty elements are written as <a/>; entity references and attribute quotes may be re-escaped, but the parsed values do not change.
Documents that use custom entities fail to parse because browsers do not expand DTD-declared entities. The parser detail explains the failure instead of guessing.
Mixed content and whitespace
The formatter only adds line breaks and indentation where an element contains element children and no meaningful text or CDATA. Elements with mixed content are kept inline, and text-only elements keep every space exactly as entered. This prevents indentation from changing the text a program or person reads.
Minification removes whitespace-only text between block children. It never removes text from mixed-content or text-only elements. If the result cannot be proved equivalent by reparsing and comparing the document structure, no output is returned.
Parser safety and limits
Parsing uses the browser's native XML parser, not HTML and not regular expressions. XML is never executed and external DTDs or entities are not fetched. A document nested more than 2,048 levels deep is rejected rather than risking a stack overflow.
Line and column numbers come from the browser's parser message when available; the technical parser detail is shown separately.
Privacy and related tools
Everything happens in this page. Your XML is not uploaded, saved in browser storage, or included in an analytics event.
To format JSON instead, use the JSON formatter; to move XML through a text-only channel, use the Base64 encoder.