How to validate XML
- Paste the XML or open the file. It is checked as you type; Validate (Ctrl + Enter) opens the Report tab.
- A broken document shows the line and column, the code around it with a caret, and a Fix: line. Go to error jumps there.
- Once it passes, Format re-indents it. The XML formatter adds Self-close empty tags.
What the XML validator reports
| You wrote | The validator says |
|---|---|
<item>Tea</itme> |
</itme> does not match <item>. and the line where <item> opened |
?id=7&ref=feed in a link |
Unescaped '&'. with the fix & |
|
Unknown entity with the fix   |
| two elements at the top level | Second root element <user>. |
<book id=42> |
Value of id must be in quotes. |
<!-- old -- do not use --> |
'--' is not allowed inside a comment. |
a blank line before <?xml |
The XML declaration must be the very first thing in the document. |
A tag left open to the end gets <catalog> is never closed., with a pointer to where it opened.
Well-formed, not schema-valid
The check covers the XML 1.0 rules every parser enforces: one root element, tags closed in reverse order, quoted attributes, & and < escaped in text. It does not validate against an XSD or DTD, so a missing required element or a non-numeric <qty> passes. Entities declared in the document’s own DOCTYPE are understood; external DTD files are not loaded.
For schema validation in a script or CI job, use xmllint from libxml2:
xmllint --noout --schema invoice.xsd invoice.xml
Java’s “Content is not allowed in prolog”
Java’s XML parser throws this when text comes before the root element, often a JSON or plain-text error body where XML was expected. Paste the response here to see what precedes the first tag, or read Content is not allowed in prolog.
Valid XML can go on to the XPath tester or XML to JSON.