XML Validator

Check that XML is well-formed and get a line-broken copy back when it parses cleanly.

How it works

The text is parsed with the browser's DOMParser in application/xml mode. If the parser produces a <parsererror>, its message is shown, trimmed to the first couple of hundred characters. If parsing succeeds, the document is re-serialised and a line break is inserted between adjacent tags so the structure is readable.

What “well-formed” means

Exactly one root element; every start tag has a matching end tag or is self-closing; tags are properly nested; attribute values are quoted; and the five reserved characters are escaped as &lt; &gt; &amp; &apos; &quot; where required. Well-formed is not the same as valid — validity is conformance to a DTD or XSD, which this tool does not check.

Worked example

Input <note><to>Ada</to><body>Hello</body></note> reports “XML is well formed.” and returns:

<note>
<to>Ada</to>
<body>Hello</body>
</note>

Change it to <note><to>Ada<body>Hello</body></note> and it reports a mismatched-tag error because <to> is never closed.

Errors it catches

ProblemExample
Mismatched or unclosed tag<a><b>x</a>
More than one root element<a/><b/>
Unquoted attribute value<a id=1/>
Unescaped reserved character<a>Tom & Jerry</a>
Undeclared namespace prefix<ns:a/> with no xmlns:ns

When to use it

Confirming that a config file, an RSS or Atom feed, a SOAP body, or an SVG parses before you feed it to something stricter, and locating an unclosed or misnested tag in a document a build tool rejected without a helpful line number.

Does it validate against a schema (XSD/DTD)?

No, only well-formedness.

Why does a stray & cause an error?

A bare & must be written &amp; unless it starts a valid entity.

Does it check that namespaces are declared?

An undeclared namespace prefix on an element does raise a parser error.

Is my document uploaded?

No, DOMParser runs in the browser.