XML Code Formatter

How to use 3 steps
  1. Paste your code under Paste XML Code.
  2. Press Format XML.
  3. Copy the formatted result.
Formatted XML Output

How this tool works

The document is split at the boundaries between tags and re-indented, with two spaces added on entering an element and removed on leaving it. That produces a readable tree from a document that arrived as one unbroken line, which is how XML usually arrives from an API or an export.

This is a formatter rather than a parser: it re-indents structure it recognises, and it does not validate. A document with a missing closing tag or a mismatched name will be re-indented as happily as a correct one, with the fault showing up only as indentation that drifts in a direction it should not.

What it will and will not handle

  • Nothing is validated: a malformed document produces malformed output rather than an error. Drifting indentation is often the first visible sign that something upstream is wrong.
  • Text between tags may not survive tidily: the split works on tag boundaries, so mixed content — text with inline elements in it — is where the output is least reliable.
  • Attributes are left exactly as they are: order, spacing and quoting inside a tag are untouched. Only the indentation between tags changes.
  • Use it to read, not to rewrite: reformatted XML is for looking at. Feeding it back into a system that cares about whitespace is a risk this tool cannot assess for you.

A formatter, not a parser

The [msm_tool slug="xml-formatter"] splits a document at the boundaries between tags and re-indents it, adding two spaces on entering an element and removing them on leaving — which turns a document that arrived as one unbroken line, the way XML usually comes back from an API or an export, into something with a readable tree shape. What it does not do is validate anything along the way: it re-indents structure it recognises rather than checking that structure is actually correct.

Drifting indentation is often the first real warning sign

A document with a missing or mismatched closing tag is re-indented just as willingly as a correct one, with no error reported anywhere — the fault shows up only as indentation that drifts in a direction it should not, rather than returning to where it started once the relevant closing tag appears. That drift is frequently the first visible clue that something upstream produced a malformed document.

Mixed content is where it is least reliable

The split works at tag boundaries, which handles pure element nesting cleanly but is less predictable for mixed content — ordinary text with inline elements sitting inside it. That combination is the case most likely to come out looking different from what a person would have chosen by hand.

Attributes are left exactly as they were

Order, spacing and quoting inside a tag are untouched throughout — only the indentation between tags changes. Anything inside the tag itself is not this tool's concern at all.

Use it to read, not to feed back in

Reformatted output is meant for looking at. Whitespace can be semantically significant depending on the schema a document is validated against, so whether reformatted XML is safe to send back into whatever system produced it is a question this tool has no way to answer on its own behalf.

Where it partly works on HTML, and where it does not

HTML permits tags that never get explicitly closed, which XML's grammar does not allow, so running HTML through this produces the same kind of indentation drift a genuinely malformed XML document would show — not because the HTML is wrong, but because this formatter is reading it as something stricter than it actually is. A formatter built specifically for HTML is the better tool for that job.

Frequently Asked Questions

Specific to the XML Code Formatter. Broader questions about this category are answered on the category page.

No. It re-indents; it does not parse or validate. A broken document is re-indented just as readily as a correct one.
Usually a missing or mismatched closing tag. The indentation only returns when it sees a closing tag it recognises.
No. Everything inside a tag is left alone — only the spacing between tags changes.
Partly. HTML permits unclosed tags that XML does not, so the indentation will drift on them. An HTML-specific formatter is the better choice.
It can be, depending on the schema. Reformatted XML is safe to read but should not be assumed safe to feed back in.

Subscribe to receive notifications about new tools, features, and productivity tips.