Skip to main content

XML Formatter

Pretty-print, validate, and minify XML with CDATA and attribute preservation.

Written by Golam Rabbani, Founder & Lead Engineer

How to use this xml formatter

  1. Paste your XML document into the input box.
  2. Pick an indent size (2 spaces, 4 spaces, or a tab).
  3. Choose Pretty print to indent, or Minify to strip whitespace.
  4. Press Format to validate and reformat the XML.
  5. Copy the result to the clipboard or click Reset to start over.

About this xml formatter

The XML formatter parses your XML, builds an in-memory tree, then re-emits the document with the indentation rules you choose. It runs entirely in your browser — nothing is uploaded — so you can safely paste configuration files, SOAP envelopes, RSS feeds, and other XML payloads that you would not want to send through an external service.

On the way in, the parser walks every tag, attribute, CDATA section, processing instruction, and comment. If it finds a mismatched or unclosed tag, it stops and reports the problem instead of producing misleading output. On the way out, the renderer keeps elements that contain only text inline, expands elements with mixed children onto separate lines, preserves attribute order, and re-escapes the five core XML entities so the result is round-trip safe.

For example, the input "<note><to>Tove</to><from>Jani</from></note>" with 2-space indent becomes: <note> <to>Tove</to> <from>Jani</from> </note>

Switching to Minify mode collapses the same document back to a single line, which is useful when embedding XML inside JSON or environment variables.

FAQ

Does the XML formatter validate the document?
It performs well-formedness checks — it confirms every tag is closed, attributes are quoted, and brackets balance. If anything fails it surfaces the message instead of producing output. It does not validate against an XSD or DTD schema.
Will it keep my CDATA sections intact?
Yes. CDATA blocks are detected by the parser and emitted unchanged, so embedded scripts, HTML, or binary-looking content survives the round trip.
What is the difference between Pretty print and Minify?
Pretty print adds line breaks and indentation so the structure is easy to read. Minify removes every optional whitespace character between tags so the document is as small as possible for transport.
Is my XML uploaded anywhere?
No. Parsing and formatting happen in your browser. The XML never leaves your machine.
Why did formatting fail with "Mismatched closing tag"?
The parser saw a </tag> that did not match the most recently opened element. Check that every opening tag has the same name as its closing tag and that nesting is correct.
Does it preserve XML declarations and DOCTYPE?
Yes. The XML declaration (<?xml ... ?>) and any DOCTYPE node are kept at the top of the document in the formatted output.