Developer tool

XML Formatter & Validator

Paste XML to check it, then make it easier to read with one click.

Runs in your browser. No upload.

XML is checked in your browser. No upload.

About this tool

XML Formatter & Validator made simple.

The browser checks that the XML is well formed and formats it locally. Your document is not uploaded; formatting does not validate an external schema or DTD.

Guide

Using XML Formatter & Validator

The XML Formatter and Validator checks that the XML you paste is well formed, which means the tags open and close in the right order and the quotation marks match, and then lays it out with two-space indentation. The check uses the browser's own XML parser. It does not test your file against an XSD schema or a DTD, and it refuses any document that contains a DOCTYPE.

How to use it

  1. Paste your XML into the large box. The tool accepts up to 2 MB of text, which is 2,097,152 characters.
  2. Press Format XML to check the text and fill the output box with the indented version. Press Check XML if you only want the well-formed test and no output.
  3. Read the status line under the box. It says the XML is well formed, or it gives a short reason, such as a DOCTYPE being refused or the tags not matching.
  4. Press Copy XML to take the formatted text, or Clear to empty both boxes. Editing the input also clears the output.

Worked examples

Indenting one long line

You enter
Xml
<?xml version="1.0"?><library><book id="1"><title>Dune</title><year>1965</year></book><book id="2"><title>Emma</title></book></library>
You get
Status
XML is well formed.
Formatted
<?xml version="1.0" encoding="UTF-8"?> <library> <book id="1"> <title>Dune</title> <year>1965</year> </book> <book id="2"> <title>Emma</title> </book> </library>

Each child element moves to its own line, two spaces deeper than its parent. Notice that the first line now also says encoding UTF-8, which the original did not state.

Run through the tool’s own code.

Text mixed with tags stays on one line

You enter
Xml
<p>Hello <b>big</b> world</p>
You get
Status
XML is well formed.
Formatted
<?xml version="1.0" encoding="UTF-8"?> <p>Hello <b>big</b> world</p>

When an element holds text between its tags, adding line breaks could change the text. The tool leaves such an element exactly as it was, so only the declaration line is added.

Run through the tool’s own code.

Tags that do not match

You enter
Xml
<a><b></a>
You get
Status
XML is not well formed. Check the tags and quotation marks.
Formatted

The element b is opened but never closed before a ends, so the parser rejects the whole document. The message does not give a line or column, so look for the nearest unclosed tag.

Run through the tool’s own code.

When it helps

  • Make a minified feed, sitemap or configuration file readable before you edit it by hand.
  • Find out quickly whether a hand-edited XML file still parses, before you load it into another program.
  • Tidy an XML snippet for a bug report, a code review or documentation.
  • Check an exported file from an app for broken tags or unescaped characters.

Limits to keep in mind

  • It checks well-formedness only. It cannot tell whether the elements and attributes follow an XSD schema or a DTD, so a file can pass here and still be rejected by a strict consumer.
  • Any document with a DOCTYPE is refused on purpose. Remove that line first if you only want the formatting.
  • The first line is always rewritten as version 1.0 with UTF-8. An original encoding such as ISO-8859-1, or a standalone flag, is dropped from the output.
  • An element that contains text next to other tags stays on one line. Repeated namespace declarations may also appear on child elements in the output, which is still valid XML but longer.

Tips

  • Fix errors from the top down. One missing closing tag early on can make every tag after it look wrong.
  • Escape the characters & and < inside text as &amp; and &lt;. A bare one is the most common cause of a not-well-formed message.
  • Keep the original file. The formatted copy changes the declaration line, so do not overwrite a source file that must stay byte for byte.

Sources

Common questions

About XML Formatter & Validator.

How do I format XML online with this tool?

Paste the XML into the input box and press Format XML. If the text is well formed, the output box shows it with two-space indentation, one element per line, and a declaration line at the top.

Does this XML validator check against an XSD or DTD?

No. It only tests that the XML is well formed. A document can be well formed and still break the rules of a schema, so use a schema validator when that matters for your project.

Why does my DOCTYPE line cause an error?

The tool refuses documents with a DOCTYPE and its message says this is for safety. Delete the DOCTYPE line, format the rest, then add the line back to your own copy if you need it.

What is the difference between Format XML and Check XML?

Both run the same test. Format XML also fills the output box with the indented text. Check XML leaves the output empty and only reports whether the XML is well formed.

Why did my encoding declaration change?

The tool builds a new declaration line, always version 1.0 with UTF-8, instead of keeping the original. If your file must stay in another encoding, copy only the body and keep your own first line.

Is there a size limit?

Yes. The input can hold up to 2 MB, which is 2,097,152 characters. A larger document shows a message asking you to process a smaller one.

Is my XML uploaded to a server?

The page says the check happens in your browser with no upload. The text goes to the browser's built-in parser. Even so, take care with files that hold passwords or keys.

How do I format XML online?

Paste your XML and select Format XML. The tool checks the syntax and adds readable indentation.

Does this XML validator check an XSD schema?

No. It checks whether the XML is well formed, but does not validate it against an external XSD or DTD.