XML Formatter
Format, indent, and minify XML documents
How to XML Formatter Online
Format, indent, and minify XML documents — RSS feeds, SOAP envelopes, configs, Android layouts.
- Paste your XML into the input box. The browser's built-in `DOMParser` validates it.
- Choose indent width (2 spaces is the modern default).
- Decide whether to keep simple leaf elements (`<title>Hello</title>`) on a single line. Leave on for most cases.
- Click Format to produce a pretty-printed version, or Minify to strip inter-tag whitespace and comments.
- If the document is malformed, the error shows the parser's exact complaint with line and column info.
- Click Copy to put the result on your clipboard.
About XML Formatter
XML is the format that refuses to die. RSS and Atom feeds are XML. SOAP envelopes are XML. Maven POMs, Spring configs, Android layouts, Java EE web.xml, .NET app.config, SVG, sitemap.xml, and the underlying format of every Microsoft Office document (XLSX, DOCX, PPTX) are all XML. Whenever you have to read or modify one of these and the source comes minified or with one element per line, the first thing you want is a clean, indented version where the structure is obvious.
This tool is built around two pieces of the browser. First, **`DOMParser`** validates your input — XML is strict, and the parser will reject unclosed tags, mismatched namespaces, undeclared entities, and malformed CDATA blocks with a clear error message. That validation happens before the formatter touches your document, so a malformed input never gets silently "repaired" into something that looks valid but is not. Second, **`xml-formatter`** (a tiny ~5 KB library) walks the validated document and re-emits it with consistent indentation and a stable choice about when to keep leaf elements on a single line.
The "keep simple leaf elements on one line" option is the difference between readable XML and pyramid-shaped XML. Without it, a feed like `<title>Hello</title>` becomes three lines: `<title>\n Hello\n</title>`. A 50-item RSS feed turns into a 300-line scroll. With it on, leaves stay compact (`<title>Hello</title>`) while structural elements still indent, which matches what Maven, the .NET XML serializer, the Java JAXB pretty-printer, and every major hand-edited XML config does.
Minification is the inverse operation and surprisingly tricky to get right. You cannot just delete all whitespace — text content inside an element is data, and stripping spaces inside `<message>Hello world</message>` changes the message. The minifier here removes whitespace **between tags only** (`> <` collapses to `><`), strips comments, and collapses runs of whitespace outside text content. The result is the smallest representation that parses to the same DOM tree.
A few things the tool deliberately does not do. It does not transform HTML — HTML5 is intentionally not well-formed XML (it allows unclosed paragraphs, self-closing tags without slashes, attribute values without quotes), so the XML parser rejects HTML5 documents. For HTML, use the dedicated HTML/CSS/JS Beautifier instead. It does not sort attributes — order is preserved exactly as the input. XML semantically treats attribute order as unspecified, but compare-by-string-equality workflows depend on stable order, and silently re-ordering would surprise people. It does not resolve external entities, validate against schemas, or fetch DTDs.
One historical hazard worth flagging: **XML external entity (XXE) attacks.** Some XML parsers, when given a document that references an external file via a DTD declaration, will fetch and inline that file — including `/etc/passwd` or an internal URL the attacker could not otherwise reach. The browser's `DOMParser` does not fetch external entities (modern browsers have all blocked this for years), so pasting hostile XML into this tool is safe. But if you are writing server-side code that parses XML, look up "XXE" for your specific library and confirm external entities are disabled by default.
Everything runs in your browser. The XML parser is native; the formatter is ~5 KB of bundled JavaScript. No network requests, no logging, no telemetry on document contents. Internal SOAP traffic, vendor RSS feeds with API keys in URLs, proprietary config files — all stay on your machine.
Related Tools
Frequently Asked Questions
Why does the formatter validate before formatting?
Because malformed XML is a real risk if you just naively reformat — a missing closing tag would silently get repaired into something the formatter thinks is valid, hiding the bug. The tool runs your input through the browser's built-in `DOMParser` first. If `DOMParser` rejects it, you get the exact error message the parser produced (line, column, and what it expected) and no output. The reformatter only runs on documents the browser would accept as well-formed XML.
What is the difference between `<![CDATA[…]]>` and regular text content?
CDATA sections wrap text that should not be interpreted as XML. Inside a CDATA section, `<`, `>`, and `&` are literal characters rather than special markup. This is how HTML, code snippets, or anything containing those characters gets embedded in XML without endless escaping. The formatter preserves CDATA exactly as written.
Does this tool work for HTML?
Partially. HTML is *almost* XML — XHTML 1.0 is strictly compliant XML, but HTML5 has self-closing tags without slashes (`<br>` instead of `<br/>`), unclosed paragraph tags, and other relaxations the XML parser rejects. For pure XML (RSS, SOAP, SVG, sitemap.xml, Android layouts, Maven POMs, Java config) it works. For HTML, use the HTML/CSS/JS Beautifier instead.
What does 'Keep simple leaf elements on one line' do?
When enabled, leaf elements with only short text content stay on a single line: `<title>Hello</title>`. When disabled, those become `<title>\n Hello\n</title>` — three lines per leaf, which can blow a dense document up to several pages. The single-line form is what every major XML-using ecosystem does in its own pretty-printed output (Maven, Spring, RSS reader exports, .NET configs, etc.).
Is the order of attributes preserved?
Yes. `DOMParser` walks attributes in source order and the formatter re-emits them in the same order. If you have a tool that compares XML by string equality across two formatted versions, you can rely on attribute order being preserved per element. Note: XML *semantically* treats attribute order as unspecified, so two documents differing only in attribute order should be considered equivalent by any compliant consumer.
Why does the minify output still have some whitespace inside text content?
Because text content inside an XML element is data — collapsing whitespace there can change meaning. The minifier removes whitespace *between tags* (`> <` becomes `><`) and inside the document outside text content, but anything inside an open/close tag pair is preserved. This is how every XML minimizer works for safety.
Is anything sent to a server?
No. Parsing uses `DOMParser` (your browser's built-in XML parser) and formatting uses the bundled `xml-formatter` library (~5 KB compressed). No network requests, no logging. Internal-system XML configs, vendor SOAP payloads, anything sensitive stays local.