XML Formatter
Format messy or single-line XML into neatly indented markup, or minify it for transport. The formatter understands XML declarations, processing instructions, comments, CDATA sections, DOCTYPE declarations and self-closing tags, and it checks that every element is properly closed and nested. The browser’s own XML parser double-checks well-formedness.
How to use the XML Formatter
- Paste your XML or click Load example.
- Choose 2 spaces, 4 spaces, Tab or Minify.
- Optionally remove comments from the output.
- Fix any reported error using the line and column shown.
- Copy or download the formatted file.
Features
- Indent with spaces or tabs, or minify to one line
- Keeps CDATA, DOCTYPE, comments and processing instructions intact
- Normalises attribute spacing without touching values
- Detects mismatched, unclosed and extra closing tags
- Second opinion from the browser’s XML parser
Benefits
- Read SOAP responses, sitemaps, RSS feeds and config files easily
- Find the exact tag that breaks a document
- Processed locally, so private data stays on your device
Frequently asked questions
Does formatting change whitespace inside elements?
Leading and trailing whitespace around text is trimmed and line breaks inside text are collapsed. If your XML relies on xml:space="preserve", check the output before using it.
Is CDATA content modified?
No. CDATA sections are copied exactly, including any < or & characters inside them.
Why does it say only one root element is allowed?
A well-formed XML document must have exactly one top-level element. Wrap multiple elements in a single parent element.
Related tools
- JSON Formatter — Beautify or minify JSON with 2-space, 4-space or tab indents, sort keys and browse it as a collapsible tree.
- JSON Validator — Check JSON syntax as you type, see the exact line and column of any error and get warnings for duplicate keys.
- HTML Formatter — Beautify HTML with your choice of indentation and line wrapping, including inline <script> and <style> blocks.
- CSS Formatter — Beautify minified CSS into readable rules with custom indentation, brace style and one selector per line.
- JavaScript Formatter — Beautify JavaScript with configurable indentation, brace style and line wrapping to make minified code readable.
- Code Minifier — Minify JavaScript with Terser, plus CSS and HTML, and see the original size, minified size and percentage saved.