Skip to content
← Back

XML Formatter - Beautify & Minify Online

Code
Runs locally · Not uploaded

Online XML formatter and minifier: pretty indentation or single-line compression, precise syntax error hints, attribute preservation and escaping. Local processing.

Was this result helpful?

For local tools, open DevTools → Network and search your input — it should not appear in requests.

Usage Guide

XML shows up in config files (Maven/Spring/Android layouts), SOAP APIs and enterprise systems — and its most common complaint is being an unreadable one-liner. This tool indents it by hierarchy, or minifies it back to a single line, using local DOM parsing so content never leaves the browser.

1. Format and minify

  1. Paste the XML (squashed or inconsistently indented, both fine).
  2. Click Format for a readable indented version; click Minify for the whitespace-free single line.
  3. Syntax errors (unclosed tags, illegal characters) are reported — fix syntax before worrying about layout.

2. XML-specific formatting edges

  • Whitespace is content: text nodes pick up indentation — for XHTML and mixed-content documents formatting can change rendering and semantics, so verify after converting.
  • CDATA blocks are preserved verbatim: formatting never touches the "looks like XML" text inside them.
  • Namespace prefixes are semantic: formatting only adjusts indentation; renaming prefixes invalidates the document.

3. Interoperating with the JSON world

Modern systems meet XML mostly at legacy boundaries. If the downstream only accepts JSON, format first to inspect the structure, then convert via XML→JSON (also on this site) — note that attributes versus child elements usually merge or get prefixed in JSON, and the exact mapping should be agreed with the consumer. This page is about readability and minification, not schema/XSD validation.

4. Three problems formatting cannot fix

  • Encoding declaration vs real bytes (says UTF-8, file is GBK) produces "garbled but well-formed" tags — fix source encoding first.
  • External entities and XXE are parser-security topics; browser DOM parsing is already conservative about external entities — never feed untrusted XML into a lax server-side parser.
  • "Parses" ≠ "valid for the business": missing required elements and bad enums need XSD/business checks, not indentation.

5. How this differs from HTML formatting

HTML is forgiving and may auto-complete; XML is strict: tags must close, names are case-sensitive, attributes need quotes. Pasting an HTML fragment as XML often fails outright — different grammar, not a broken tool. Android layouts, pom.xml, and SOAP envelopes are this page's home turf; use the HTML formatter for page fragments.

6. Team workflow

Format before commit so diffs focus on real node changes instead of indent thrash — but be careful with mixed content, where "layout-only" commits can still alter text-node whitespace. Agreeing on indent width and "no minified one-liners in the repo" is cheaper than debating personal taste. Minify mode fits transport embeds and single-line logs, not human review.

7. Pretty-print acceptance

Paste full XML, pick indent width, and confirm hierarchy stays readable. Invalid structure should error rather than silently drop nodes. Formatting is local. For XML↔JSON, use sibling converters only after the XML parses.

FAQ

Different grammar: XML is a tag tree (attributes, namespaces), JSON is data. This tool indents per XML semantics and preserves escaping of & < > ".

Yes — the browser DOMParser understands xmlns and prefixes are preserved in output. Prefixes are part of the semantics; rewriting them would break document validity.

Mostly whitespace: indentation and line breaks. Attribute order, text, and escaping are kept where possible; in mixed-content docs, indentation can alter text-node whitespace — verify afterward. CDATA blocks are preserved verbatim, never rearranged. Minify removes compressible whitespace.

Not recommended. HTML is forgiving and auto-completes; XML is strict: tags must close, matching is case-sensitive, attributes need quotes. Use the HTML formatter for page fragments; Android layouts, pom.xml, and SOAP are this page's home turf.

No. This page covers readability and minification only — parsing cleanly is not the same as being business-valid. Missing required elements or wrong enum values need an XSD or business-level validation, not indentation.

Formatting parses the document locally via the DOM and makes no network requests — the content never leaves your browser. That said, config-style XML often carries credentials: sanitize it before sharing anywhere, and clear the clipboard residue when you are done.

Related Tools

Related Articles