Skip to content

XML Formatter & Validator

Pretty-print, minify and validate XML in your browser. Well-formedness is checked locally and nothing you paste is ever uploaded.

Runs entirely in your browser. Nothing you paste here is sent to us or anyone else โ€” there is no server processing, no logging of input, and no third-party scripts on this page.

An XML formatter takes raw, single-line or messy XML and pretty-prints it with clean, consistent indentation โ€” or minifies it back down โ€” while checking that the document is well-formed and pointing to the exact line and column of any error. The tool above does all of this in your browser: paste XML on the left, get formatted output on the right, then copy or download the result. Nothing you paste is transmitted anywhere.

What is XML?

XML (eXtensible Markup Language) is a text-based format for storing and exchanging structured data using nested tags. Unlike HTML, which has a fixed set of tags for describing web pages, XML lets you invent your own element names to model whatever your data needs. It powers configuration files, document formats such as DOCX and SVG, RSS and Atom feeds, SOAP web services, sitemaps, and countless enterprise data exchanges.

A small XML document looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<book id="bk101">
  <author>Gambardella, Matthew</author>
  <title>XML Developer's Guide</title>
  <price>44.95</price>
</book>

What does an XML formatter do?

XML from an API, a feed, or an export often arrives collapsed onto a single line with no indentation. That is efficient to transmit but very hard to read. A formatter parses the markup into a document tree, confirms it is well-formed, then re-serialises it with one element per line and consistent indentation so the nesting is obvious at a glance. Minifying does the reverse: it strips the whitespace between tags to make the payload as small as possible, without altering any text content or attribute values.

This tool uses the browser’s own DOMParser to parse and check the document, then walks the resulting tree to rebuild the indented output. Because parsing must succeed before anything can be pretty-printed, formatting doubles as a well-formedness check.

Well-formed versus valid

These two terms are often confused, and they mean different things:

Well-formed Valid
Follows XML syntax rules: matched, properly nested tags, quoted attributes, a single root element. Also conforms to a schema (DTD or XML Schema) that defines which elements and attributes are allowed.
Checked by this tool, entirely in your browser. Requires the schema, which this tool does not process.

Every valid document is well-formed, but a well-formed document is not necessarily valid against a particular schema. This formatter checks well-formedness โ€” the foundation every XML parser requires first.

Common XML errors and how to fix them

  • Tag mismatch โ€” a closing tag does not match the element it is meant to close, for example <b>...</a>. Make the names match and check the nesting order.
  • Unclosed tag โ€” an element is opened but never closed, which triggers a “premature end of data” error. Add the missing closing tag or use a self-closing form such as <br/>.
  • Multiple root elements โ€” a well-formed document must have exactly one top-level element. Wrap siblings in a single container.
  • Unquoted attribute values โ€” every attribute value must be inside single or double quotes.
  • Unescaped special characters โ€” a raw &, <, or > inside text breaks parsing. Use the entities &amp;, &lt;, and &gt;, or wrap the content in a CDATA section.

When parsing fails, the status line reports the line and column so you can go straight to the problem instead of scanning the whole document.

Common use cases

  • Reading an API or SOAP response that arrived minified on one line.
  • Inspecting an RSS or Atom feed, a sitemap, or an SVG file.
  • Validating a config file is well-formed before committing or deploying it.
  • Minifying XML to reduce payload size for storage or transport.
  • Diffing two documents by formatting both with the same indentation first.

Is it safe to paste sensitive XML here?

Yes โ€” this tool never sends your input anywhere. Parsing, validation, and re-serialisation all happen with the browser’s native XML parser, on your device. There is no server round-trip, no logging, and no third-party analytics on this page. As with any online tool, treat the most sensitive payloads with healthy caution: our source is open so you can verify the behaviour, and once the page has loaded you can disconnect from the network and it will still work.

Frequently asked questions

Is my XML sent to a server?

No. Formatting and validation happen entirely in your browser using its built-in DOMParser. Nothing you paste is uploaded, logged, or stored, and the tool keeps working if you disconnect from the internet after the page loads.

What does "well-formed" mean?

Well-formed XML follows the basic syntax rules: every element has a matching closing tag, tags are properly nested, attribute values are quoted, and there is exactly one root element. This tool checks well-formedness. It does not validate against a DTD or XML Schema, which is a separate, stricter step.

Why does it say "tag mismatch" or "premature end of data"?

Those errors mean the XML is not well-formed. A mismatch usually means a closing tag does not match the element it closes or the nesting is wrong; a premature end means a tag was never closed. The status line reports the line and column so you can jump straight to the problem.

What is the difference between formatting and minifying?

Formatting (pretty-printing) adds indentation and line breaks so the structure is readable. Minifying removes the whitespace between tags to shrink the document for transport or storage. Both describe the same data.

Does formatting change my data?

It only changes the whitespace between elements. Text content, attribute values, CDATA sections, and comments are preserved exactly. Character entities such as &amp;amp; and &amp;lt; are kept so the output stays valid.

Can it handle an XML declaration and comments?

Yes. The <?xml ... ?> declaration at the top is preserved on its own line, and comments, CDATA blocks, and processing instructions are kept in place when you format or minify.

Will it fix broken XML for me?

No. A formatter can only reformat XML that already parses. If the document is not well-formed it reports the error instead of guessing, because silently repairing markup would risk changing your data.

How is XML different from HTML?

XML is strict: tags are case-sensitive, every element must be closed, and attribute values must be quoted. HTML is more forgiving and has a fixed vocabulary of tags. XML lets you define your own element names for arbitrary structured data.