XML formatter and validator

Paste XML or open a file. It is checked as you type, indented the way you choose or minified, and an error comes with its line, column and what is wrong. Comments, CDATA, the doctype and the order of attributes stay as they were.

Paste it, drop a file on the box, or open one. Nothing is uploaded.
Output

Paste XML into the box to format and check it.

XML turns up in server work all the time: sitemaps, RSS feeds, Maven builds, libvirt and Tomcat configs. Looking for the server itself? From €3.02 a month today, among 2,226 servers.

Works in your browser: nothing you type is sent anywhere.

How the XML formatter works

The page reads your XML into its parts: tags, attributes, text, comments, CDATA sections, processing instructions like <?xml …?> and the doctype. Then it writes them out again, each element on its own line, indented one level per depth with 2 spaces, 4 spaces or a tab. Minify does the opposite and removes the whitespace between tags.

Only the whitespace between tags changes. Text is kept character for character, attributes stay in their order with their quotes, and comments, CDATA and the doctype are copied as written. Where text and tags are mixed, like <p>Hello <b>world</b></p>, or where xml:space="preserve" is set, the spaces matter, so that part is left exactly as it was.

To validate, the page also hands your XML to your browser's own XML parser (DOMParser), the same one that reads RSS and SVG files. It checks that the document is well-formed: one root element, every tag closed in the right order, quoted attributes, no attribute twice, known entities only. Errors are shown with their line and column. It does not check against a schema (XSD or DTD) and never fetches external files.

Example

A small config, minified on one line:

config.xml
<?xml version="1.0"?><config><!-- web tier --><server name="web-1" port="443"><tls enabled="true"/><root>/var/www</root></server></config>

Formatted with 2 spaces it becomes the version below. The comment, the self-closing <tls/> tag and the order of the attributes are unchanged; minifying it again gives back the exact line above.

formatted.xml
<?xml version="1.0"?>
<config>
  <!-- web tier -->
  <server name="web-1" port="443">
    <tls enabled="true"/>
    <root>/var/www</root>
  </server>
</config>

Questions

How do I format XML?

Paste it into the box above, or open the file, and choose 2 spaces, 4 spaces or a tab. The formatted XML appears on the right as you type; copy it or download it as a file. On the command line, xmllint --format file.xml does the same on Linux and macOS.

How do I check if XML is valid?

Paste it above: the page says whether it is well-formed, and if not, gives the line, the column and the reason, such as a closing tag that does not match. Well-formed means the syntax is right. Checking it against a schema (an XSD or DTD) is a separate step, for example with xmllint --schema schema.xsd file.xml.

Does formatting change my XML?

Only the whitespace between tags, which XML programs normally ignore. Text, attribute values and their order, comments, CDATA, processing instructions and the doctype stay exactly as written. Mixed content (text with tags inside) and anything under xml:space="preserve" is not touched at all, because there the spaces can matter.

What is the difference between well-formed and valid XML?

Well-formed XML follows the syntax rules: one root element, every tag closed and properly nested, attribute values in quotes, no attribute twice. Valid XML is well-formed and also follows a schema or DTD that says which elements and attributes are allowed. A parser can read any well-formed file; only validation tells you it has the right structure.

Is it safe to paste XML with passwords or keys here?

Yes. Formatting and checking run in your browser, and nothing you paste is sent to a server or stored. The browser's XML parser does not download external DTDs or entities either. Closing the tab removes the text.