XML Formatter: Format and Minify XML Documents

Parse well-formed XML in this browser, then pretty-print or minify it from the DOM tree — not with a regex indent. Indent width, attribute wrapping, and empty-element style are under your control. Parse errors report line and column when the engine provides them. Document type definitions and external entities are never fetched. Nothing is uploaded.

Format options
Load file

Drop an .xml, .svg, or related text file here. Client-only FileReader, UTF-8.

Output is rebuilt from the parsed DOM. Insignificant inter-element whitespace is normalized.

Paste XML and press Pretty-print. Results stay in this browser.

How to read the result

A green status means the input is well-formed XML 1.0 as this browser’s parser defines it: one root, matched tags, quoted attributes, and legal characters. That is not the same as being valid against an XSD, DTD, Relax NG, or Schematron schema. Red status is a fatal well-formedness error. Amber notes mean the document parsed, but a DOCTYPE, entity declaration, or encoding rewrite needs attention.

Pretty-print walks the DOM and emits indentation between element-only children. Mixed content (text plus child elements) and xml:space="preserve" regions keep their character data so formatting does not invent spaces. Minify removes insignificant whitespace between elements. CDATA stays opaque. Use Ctrl+Enter or ⌘+Enter to pretty-print.

Privacy and parser limits

  • All work runs locally with DOMParser and a custom serializer. There is no network call for formatting, and this page does not write persistent client storage.
  • External DTD subsets, SYSTEM/PUBLIC identifiers, and external entities are never fetched. That blocks classic XXE. Custom entities declared in a DOCTYPE are usually not expanded by the browser either, so &foo; often fails as an undeclared entity.
  • DOCTYPE nodes are detected and omitted from output. Default attributes from a DTD are not applied.
  • The XML declaration’s encoding is informational once text is already Unicode in the textarea. Output declarations use UTF-8. Files are read as UTF-8.
  • Input is capped at 1.5 MB and about 80,000 nodes so a huge document cannot freeze the tab.

What this tool is for

Use it to read SOAP envelopes, RSS or Atom feeds, SVG, Maven POM files, Android manifests, and other well-formed documents. It will not repair broken markup, fetch a schema, or canonicalize exclusive C14N for signatures. Signed XML may still parse, but pretty-printing changes bytes and will break a detached signature over the original octet stream.