Developer Tools

XML Formatter & Validator

Beautify XML and leave mixed content alone.

  • Runs in your browser
  • Free, no signup

Paste XML to tidy it, compact it or check it. Anything malformed is reported with the line it went wrong on. Nothing is uploaded — the parsing happens in this page.

Parsed by your browser's own XML parser, which has no network access and no filesystem access, so an external entity has nothing to fetch and nothing to read. Documents that declare their own entities (<!DOCTYPE with <!ENTITY) are refused outright, because those can be made to expand into gigabytes.

Up to 2 MB. Pasting something larger is refused rather than quietly freezing the tab.

Applies to the formatted output. Minify removes the indentation altogether.

Your document is parsed by your browser's own XML parser and never leaves the page.

XML is unambiguous about structure and completely indifferent to layout, which is why the same document arrives as one unreadable line from an API and as forty evenly indented lines from a config file. Tidying it is safe only if you know which whitespace is content.

That is the rule this formatter follows. An element whose children are all elements is laid out on separate lines; an element that contains text is left exactly as it was, because inserting a newline around inline text adds a text node the document did not have. Namespaces, attributes, CDATA sections and comments all survive, and `xml:space="preserve"` is honoured wherever it appears.

How to use this tool

  1. Paste XML into the box, or press Example for a document with attributes, a comment and a CDATA section.
  2. Press Format to lay it out, Minify to collapse it, or Validate to check it without producing output.
  3. If it will not parse, the line and column are reported — and so is the parser's own description of the fault.

Mixed content is left alone

An element like `<p>Hello <b>world</b>!</p>` contains text and elements together. Reindenting it would put a newline and spaces before `<b>`, and those characters are text — the document would now render differently. A formatter that does this is not beautifying the document, it is editing it.

So the rule is: if an element holds any non-whitespace text or a CDATA section, its contents are emitted exactly as they fall. Everything else is indented normally. The result is that formatting is always safe, even on documents whose whitespace matters.

Why documents with a DOCTYPE are refused

An XML document can define its own entities, and an entity can expand into more entities. A few hundred bytes can describe a document that expands to gigabytes — the "billion laughs" pattern — and a document can also point at an external file or URL. Both are risks that a formatter has no business taking on somebody's behalf.

The browser's XML parser is already isolated: it has no network access and no filesystem access, so an external entity has nothing to reach. On top of that, this page refuses any document containing a DOCTYPE, and says so before you paste anything. For formatting, removing the DOCTYPE line changes nothing about the structure.

Namespaces, attributes and CDATA

Namespaces are treated as part of the name, so `<svg:rect>` keeps its prefix and `xmlns:svg` stays where it was declared. Attributes are re-emitted with their values escaped, including the quotes that would otherwise end the value, and whether an element is empty is preserved rather than collapsed or expanded.

CDATA is kept as CDATA, because its point is to hold text that must not be parsed — `<`, `&` and all. Converting it to escaped text would produce the same value and a different document, and the reason someone wrote CDATA is usually that they wanted it left alone.

Frequently asked questions

Will formatting change my XML?

The structure and the values are preserved exactly. The only change is whitespace between elements, and only where that whitespace was purely for layout — mixed content and anything under xml:space="preserve" is left untouched.

Why is my DOCTYPE rejected?

A DTD can declare entities that expand without limit, so the whole class of document is refused rather than inspected. Remove the DOCTYPE line and the rest formats normally.

Is my XML uploaded?

No. It is parsed by your browser's own XML parser and never leaves the page.

Can it convert XML to JSON?

No, deliberately. XML has attributes, text and children with no single correct JSON shape, so any conversion would be a guess about your data. YAML to JSON is offered, because both use the same data model.

Does it validate against a schema?

It checks that the document is well formed XML, which is what "valid" means to a parser. Validation against an XSD or a DTD is a different job and is not offered here.