Skip to content

XML Formatter

Pretty-print XML with clean indentation, or collapse it back to one line.

Quick Tool Overview

The XML Formatter re-indents a document so its structure is visible: one element per line, children under their parent, text-only elements left on a single line, and CDATA, comments and the declaration preserved exactly.

What it does
Re-indents XML, or collapses it back to one line
You give it
Any well-formed XML document
You get back
Readable XML with consistent indentation
Best for
SOAP envelopes, RSS feeds, config files and exports
Developer Tools Free, unlimited use No sign-up Runs in your browser

About the XML Formatter

Machine-written XML arrives as one enormous line. The formatter re-indents it so the structure is visible: one element per line, children indented under their parent, and attributes left on the opening tag where they belong.

A few decisions make the output genuinely readable rather than merely indented. An element holding nothing but text stays on one line, because splitting it would change the content of a whitespace-significant document. Empty elements collapse to the self-closing form. CDATA sections, comments and processing instructions are preserved exactly, and the XML declaration is kept at the top. If the document does not parse you get the line number and what was expected instead.

Key features of the XML Formatter

Text elements stay on one line

A tag wrapping nothing but text is not split, because breaking it would change the content of a whitespace-significant document.

CDATA and comments survive

CDATA sections, comments and processing instructions are copied through untouched, and the declaration stays on the first line.

Empty elements collapse

An element with no content is written in the self-closing form, which is shorter and unambiguous.

Errors are located

A document that will not parse reports the line and names the mismatched, unclosed or stray tag.

Namespaces are safe

Prefixed names such as soap:Envelope and xmlns attributes pass through formatting unchanged.

How to use the XML Formatter

  1. 1

    Paste your XML

    A config file, an API response, an RSS feed or a SOAP envelope.

  2. 2

    Choose the indentation

    Two spaces, four spaces or a tab, to match the rest of your project.

  3. 3

    Fix any errors

    An unparseable document reports the line and the mismatched or unclosed tag.

  4. 4

    Copy or download

    Take the formatted document to your clipboard or save it as .xml.

Frequently asked questions

Only whitespace between elements. Text inside an element is preserved, attributes keep their values, and CDATA is copied through untouched.

Reviews of the XML Formatter

What people who use the XML Formatter think of it. Reviews come from visitors and are posted as written.

No ratings yet

Yours would be the first.

  • 5 0 reviews rated 5 stars
  • 4 0 reviews rated 4 stars
  • 3 0 reviews rated 3 stars
  • 2 0 reviews rated 2 stars
  • 1 0 reviews rated 1 star

Write a review

Used this tool? Your rating helps the next person decide.

Your rating

Plain text only — links, email addresses and HTML are not accepted. Your name and review are shown publicly; nothing else is collected. See the privacy policy.

0 reviews

Newest first

No reviews yet

Be the first to rate the XML Formatter. It takes half a minute and no account.

Write the first review

More developer tools