XML Formatter
Indents XML so the structure is visible, or strips the whitespace back out again.
Results
What this tool does
XML arrives from a system that had no reason to make it readable — one enormous line with three thousand tags on it. Indenting it turns the structure into something you can scroll through and follow. Comments, CDATA sections and the XML declaration are kept exactly as they are; short text between an opening and a closing tag stays on the same line, because splitting <titulo>Os Maias</titulo> over three lines helps nobody.
Formula
each tag on its own line, with the indentation following the depth
Variables
| Symbol | Meaning | Unit |
|---|---|---|
text | XML | — |
mode | What to do | — |
indent | Spaces of indentation | — |
OUT | Formatted XML | — |
TG | Tags | — |
DP | Nesting depth | — |
SA | Size after | B |
Worked example
- XML<livro id="1"><titulo>Os Maias</titulo><autor>Eça de Queirós</autor></livro>
- What to dopretty
- Spaces of indentation2
- Formatted XML<livro id="1"> <titulo>Os Maias</titulo> <autor>Eça de Queirós</autor> </livro>
- Tags3
- Nesting depth2
- Size after83 B
Limitations
- The calculation runs entirely in your browser. The values you type are never sent to a server.
Frequently asked questions
Is whitespace in XML significant?
Sometimes, and that is the catch. In a document made of records — a configuration file, a feed, an invoice — the whitespace between tags means nothing and indenting it is safe. In mixed content, where text and tags sit side by side in a sentence, the spaces are part of the text and reformatting changes the meaning. This tool trims the whitespace between tags, so use it on structured documents and be careful with prose.