Skip to content
DoItJag

XML Formatter

Turn one-line or messy XML into neatly indented, readable markup. Text content is copied exactly, so the data never changes.

or drop a file here · .xml, .txt · up to 20 MB

Options

About the XML Formatter

XML arrives in many shapes: a SOAP response on one line, a plugin-made sitemap, a Tally export. The formatter puts every element on its own line and indents it by its depth, so the structure becomes visible at a glance.

When to use it

  • A web service returned a single line of XML and you need to find one field.
  • Two exports need the same layout so that the text compare tool shows only real differences.
  • You are about to commit a configuration file and want consistent indentation.

Worked example

Select Try an example to load a one-line catalogue with two books, keep 2 spaces and select Format XML.

The catalog element opens on the line after the declaration. Each book starts on its own line two spaces in, and its title, price and tags sit four spaces in, with each tag another two spaces deeper. A title is printed on one line together with its text, so “Clean Code” reads exactly as before. Had the value contained two spaces in a row, both would survive.

What changes and what does not

  • Only whitespace between elements that contain other elements is changed.
  • An element holding text, a mix of text and tags, a CDATA section or the attribute xml:space=“preserve” is copied character for character.
  • Attributes keep their order and quote style; extra spaces between them are reduced to one.
  • The XML declaration, DOCTYPE and processing instructions stay at the top.
  • Comments stay unless you tick Remove comments.

Good to know

  • The input must be well-formed. Otherwise nothing is formatted and you see the first problem with its line and column. The XML validator explains each kind of error.
  • DTD entities are not expanded and nothing is fetched from the internet, so a hostile file cannot read local files or exhaust memory.
  • To shrink a file instead, use the XML minifier.

How to use XML Formatter

  1. Paste XML or open an .xml file.
  2. Choose the indentation and whether to remove comments.
  3. Select Format XML, check the result, then copy or download it.

Privacy: how it works

Everything happens in your browser. Your text is not sent to any server.

Frequently asked questions

Will formatting change my data?

No. Only the whitespace between elements is changed. Any element that contains text, including mixed text and tags or xml:space="preserve", is copied character for character.

What happens if my XML has an error?

Nothing is formatted. You see the first problem with its line and column, for example a closing tag that does not match, so you can fix it and try again.

Does it check my XML against a schema (XSD or DTD)?

No. It checks that the XML is well-formed, which is what every XML parser needs. Validation against a schema is not included.