What the XML Validator does
The XML Validator checks well-formedness using the browser's standards-based XML parser and reports the first error with its line and column.
XML Validator example
The built-in sample
Input
<users><user id="1"><name>Ada</name></user><user id="2"><name>Lin</name></user></users>Output
Valid, well-formed XML.This is the input that the Load sample button fills in.
Each output was produced by running this tool on the input above it.
Details and limits
- Well-formed is not the same as valid. The document is not checked against a DTD or an XSD, so a wrong element name or a missing required attribute is not an error here.
- Namespaces are checked: a prefix that is used without an
xmlns:declaration is reported. - Only the five predefined entities and numeric references are known. An HTML entity such as
is reported as "Entity 'nbsp' not defined"; write . - The wording of the messages comes from the browser's parser and differs between browsers. Chromium-based browsers report a line and column.
Common errors
| Message or symptom | What it means |
|---|---|
| Opening and ending tag mismatch | An element is closed with a different name or in the wrong order. XML names are case-sensitive. |
| EntityRef: expecting ';' | A bare & in text. Write &amp; or use a CDATA section. |
| Extra content at the end of the document | More than one root element. Wrap the elements in a single root. |
| Namespace prefix is not defined | A prefix such as soap: is used without its xmlns declaration. |
Worked example: Catching case-sensitive tag mismatches and unescaped ampersands in XML
Unlike HTML browsers—which forgive unclosed tags and bare & characters—the W3C XML 1.0 specification requires strict well-formedness. Suppose you validate this 6-line XML product feed:
1: <?xml version="1.0" encoding="UTF-8"?>
2: <Catalog>
3: <Item id="101" featured="true">
4: <Title>R&D Lab Sensor</Title>
5: </item>
6: </Catalog>
- Error 1 on Line 4 (
R&D): An unescaped&is illegal in XML text because the parser expects an entity reference (&,<,>,", or'). ReplaceR&DwithR&D. - Error 2 on Line 5 (
</item>): XML tag names are strictly case-sensitive. Opening<Item>with a capitalIand closing with</item>(lowercasei) fails with an opening/closing tag mismatch.
Limits and what this tool cannot do
- Checks XML well-formedness, not external XSD / DTD / RelaxNG schema validation: This validator verifies W3C XML 1.0 syntax rules (single root element, properly nested case-sensitive tags, quoted attributes, valid entity references, and namespace prefixes). It does not fetch external
.xsdschema files to check whether specific business element names or data types are permitted. - External XML Entities (XXE) are disabled:
<!ENTITY>declarations referencing externalhttp://orfile://URIs are not resolved in the browser.
Questions
Can it validate against an XSD or DTD?
No. It checks that the document is well-formed. Schema validation needs the schema and a validating parser, which a browser does not provide.
What are the only 5 predefined named entities allowed in XML without a DTD?
Unlike HTML (which has hundreds of named entities like or ©), XML defines only five: & (&), < (<), > (>), " ("), and ' ('). Using in an XML file without defining it throws an undefined entity error; use instead.
Why did my XML fail when had a blank line before it?
In the XML specification, if an XML declaration (<?xml...?>) is present, it must be at the very first character of Line 1, Column 1 with zero leading spaces or blank lines before it.
Can an XML document have two top-level elements side by side?
No. Well-formed XML requires exactly one root element that wraps all other elements in the document.