XML Formatter
Beautify or minify XML documents instantly in your browser. Handles processing instructions, CDATA sections, DTD declarations, and warns on malformed XML.
The XML Formatter & Minifier is a free, browser-based tool that instantly beautifies or compresses any XML document. All processing runs entirely in your browser — no files are ever uploaded to a server.
Features
| Feature | Detail |
|---|---|
| Beautify | Re-indents XML with consistent depth-based indentation |
| Minify | Strips comments and whitespace between tags to produce the smallest output |
| Indent options | Choose 2 spaces, 4 spaces, or tabs |
| Inline text nodes | Short single-value elements like <name>Alice</name> stay on one line |
| Well-formedness check | Uses the browser's built-in DOMParser to warn about malformed XML |
| Processing instructions | <?xml … ?> and custom <?target … ?> are preserved and formatted |
| CDATA sections | <![CDATA[…]]> blocks are passed through untouched |
| DOCTYPE & DTD | <!DOCTYPE> and internal DTD declarations are preserved |
| Load from file | Upload .xml, .xsl, .xslt, .svg, .rss, .atom, .plist files |
| Copy & Download | One-click copy or save as .xml or .min.xml |
How to Use
- Paste your XML into the input area, or click
Load fileto upload a file. You can also drag-and-drop a file onto the text area. - Select Output mode:
Beautifyto add indentation, orMinifyto compress. - Choose an Indent style (active in Beautify mode only).
- Click
Beautify XMLorMinify XML. - If the input is not well-formed XML, a warning is shown — the formatter will still attempt to process it.
- Copy the result or click
Downloadto save the file.
How the Formatter Works
Tokenizing
The source is scanned character by character into typed tokens — processing instructions, comments, CDATA sections, DTD declarations, opening tags (including self-closing), closing tags, and text nodes. Attribute values are scanned with quote-awareness so that > or < characters inside attribute values are never misinterpreted as tag boundaries.
Beautifying
Each token is placed on its own line at the correct indentation depth. There is one exception: if an opening tag is immediately followed by a short text node and then its closing tag (e.g. <city>London</city>), all three are collapsed onto a single line for readability. The <?xml … ?> prolog, if present, is always placed at the top with no indentation.
Minifying
All comments are removed. Whitespace-only text nodes between tags are dropped. Text nodes that contain actual content have their internal whitespace collapsed to single spaces. Attribute values and CDATA sections are never modified.
Well-Formedness Validation
After formatting, the tool passes the original input through the browser's built-in DOMParser using the application/xml MIME type. If the parser detects an error, a warning message is displayed with the parser's error description. The formatted output is still shown — you can use the warning to identify and fix structural issues.
Common reasons for validation warnings:
- Missing closing tags
- Unescaped
<,>, or&characters in text content (use<,>,&) - Multiple root elements (XML allows only one root)
- Invalid characters in tag or attribute names
- Mismatched namespace prefixes
Common Use Cases
- Formatting API responses in XML format (SOAP, OData, REST with XML output)
- Reading and editing RSS or Atom feeds
- Inspecting Android
.xmllayout or resource files - Formatting SVG files for readability
- Reading Apple
.plistconfiguration files - Compressing XSLT stylesheets for deployment
- Debugging malformed XML from third-party systems
Frequently Asked Questions
Does this tool validate XML schemas (XSD)?
No. The tool checks only that the XML is well-formed (correctly nested tags, proper quoting, single root element). Schema validation against an XSD requires a separate validator.
Can I format SVG files with this tool?
Yes. SVG is XML-based and formats correctly. Load the file or paste the SVG source directly.
Are my files uploaded to a server?
Never. All processing happens locally in your browser using JavaScript. Your XML data is never transmitted anywhere.
What happens to CDATA sections when minifying?
<![CDATA[…]]> blocks are preserved exactly as-is. Their internal content is never modified in either Beautify or Minify mode.
Why does the well-formedness check show a warning on valid XML?
The browser's DOMParser is strict about XML. Some documents that are technically valid (e.g. those with an internal DTD subset or certain XML 1.1 features) may trigger false warnings in specific browsers. The formatted output is still correct.
What is the difference between XML and HTML formatting?
XML is case-sensitive, all tags must be closed, and there are no "void elements" — every tag must either have a closing tag or be self-closed with />. The XML formatter enforces these rules, whereas an HTML formatter handles the special void-element list (<br>, <img>, etc.) from the HTML specification.