XML Formatter

Pretty-print or minify XML without touching its content

Input

Output

Paste your input on the left and the result shows up here.

Or drop a file on this box, , or .

What is XML Formatter?

Got a one-line SOAP response or a config file somebody saved without line breaks? Paste it here and the XML comes back indented with each element on its own line, which makes it readable again. The output updates as you type.

What changes is the whitespace between tags, and only that. Your <?xml ...?> line and any DOCTYPE are copied character for character, comments, processing instructions and CDATA blocks survive, and an element that mixes text with child tags, such as <note>Call <b>Maeve</b> first</note>, or carries xml:space="preserve", is written out on one line just as it came in. The single exception is a text-only element like <plan> whose value someone wrapped onto its own line: that value is pulled back next to its tags.

The document is read by your browser's own DOMParser, in this tab, with nothing sent off. That also means the formatter is exactly as strict as the W3C XML specification: one unclosed tag or bare & and you get the parser's line-and-column message in red, not a best guess. Files up to 5 MB are accepted; past that the page suggests xmllint --format.

How to Use the XML Formatter

There is no Format button. Paste, choose an indent width, and the formatted copy is already waiting on the right.

1

Paste, Upload, or Load Sample

Start with the one-line XML: paste it into the input editor, or open the file through Upload (it takes .xml). Sample loads two subscriber records, SUB-1001 on Verizon and SUB-1002 on AT&T, with an XML declaration and id attributes, all on a single line. A shorter input of the same kind:

<subscribers><subscriber><subscriberId>SUB-1001</subscriberId><plan>Unlimited 5G</plan><dataUsage>45.2</dataUsage></subscriber></subscribers>

A broken document leaves the output empty and puts a red bar above it starting with Invalid XML, followed by whatever line and column the browser parser reported.

2

View Formatted Output

The right Output panel shows the formatted XML. Pick 2 spaces, 4 spaces or Tabs from the indentation menu next to the input buttons. Formatting checks well-formedness only; it does not validate against an XSD or DTD.

3

Copy, Download, or Minify

Click Copy or Download to grab the result. Minify switches the output to a single line with the indentation removed; changing the indentation menu switches back to formatted output. Use Clear to start fresh.

When You'd Actually Use This

API Development

Format XML responses from SOAP services or REST APIs that return XML, so you can see the structure and spot the element that is missing. Pairs well with browser dev tools when the network tab shows one long line.

Config File Review

A Maven pom.xml or a log4j2.xml that a build tool rewrote on one line is miserable to review. Indent it here with the same width your repo uses, and a diff against the previous version shows the setting that changed instead of one giant changed line.

Learning XML

If you are learning XML, the Sample is a decent first read. Once it is indented you can see that both subscriber elements sit under one root, that id lives on the tag while plan and status are child elements, and that the ampersand in AT&T has to be written as & in the source.

Debugging

Formatting makes nesting visible, which helps you see where an element ended up in the wrong parent. If the document is broken, the parser's error message tells you the line and column to look at.

Common Questions

Is my XML uploaded?

No. Formatting happens in your browser with JavaScript; the XML never leaves your computer.

What does the formatter change?

Only the whitespace used for indentation between elements, plus the trimming of a value that was wrapped onto its own line. Names, attributes, text, comments, CDATA, processing instructions, the XML declaration and the DOCTYPE are kept. Entity references such as &#233; come out as the character they stand for, which means the same thing to any XML parser.

Can I format invalid XML?

No. If the XML is not well-formed, you get the parser's error message instead of output, because guessing at broken markup can change your data. Fix the reported line, or try the XML Fixer, then format again.

What indentation does it use?

Two spaces by default. Switch to four spaces or tabs with the indentation menu next to the input buttons.

Why is one element still on a single line?

It either has mixed content (text and child elements together) or xml:space="preserve". Adding line breaks there would change the text, so it is left as it was. The white space section of the XML spec explains why that whitespace counts.

How big can my file be?

Up to 5 MB. Larger files are refused to keep the page responsive; xmllint --format from libxml2 handles big files on the command line.

Other XML Tools You Might Need

Readable XML is usually step one. Depending on what you do next, one of these picks up where the formatter stops: