XML Formatter

Format messy or single-line XML into neatly indented markup, or minify it for transport. The formatter understands XML declarations, processing instructions, comments, CDATA sections, DOCTYPE declarations and self-closing tags, and it checks that every element is properly closed and nested. The browser’s own XML parser double-checks well-formedness.

How to use the XML Formatter

  1. Paste your XML or click Load example.
  2. Choose 2 spaces, 4 spaces, Tab or Minify.
  3. Optionally remove comments from the output.
  4. Fix any reported error using the line and column shown.
  5. Copy or download the formatted file.

Features

Benefits

Frequently asked questions

Does formatting change whitespace inside elements?

Leading and trailing whitespace around text is trimmed and line breaks inside text are collapsed. If your XML relies on xml:space="preserve", check the output before using it.

Is CDATA content modified?

No. CDATA sections are copied exactly, including any < or & characters inside them.

Why does it say only one root element is allowed?

A well-formed XML document must have exactly one top-level element. Wrap multiple elements in a single parent element.

Related tools