Skip to content

XML XSD Validator

Check one or more XML files against an XSD schema with libxml2, the engine behind xmllint. Errors come with line numbers, the offending line and a plain-English explanation, and imported schemas are matched up for you. Nothing leaves your browser.

More XML files to check against the same schema
Supporting schemas for xs:import, xs:include and xs:redefine

What the validator checks, step by step

The tool runs xmllint from libxml2 2.13, compiled to WebAssembly by the xmllint-wasm project, in a background worker in your browser. It is the same check as xmllint --noout --schema invoice.xsd invoice.xml on a command line. First libxml2 compiles the schema, including every file it imports or includes. Then it parses each XML file. Only a well-formed file is checked against the schema rules.

Each stage can stop the check, so the result tells you which stage failed:

Validation results and what to do next
ResultWhat happenedWhat to do
ValidEvery XML file parsed and matched the schemaNothing
Doesn't match the schemaWell-formed XML that breaks schema rulesFix each listed line; earlier errors can cause later ones
XML syntax errorA file isn't well-formed, so it wasn't checkedFix the first syntax error, then validate again
Schema errorThe XSD didn't compile, so no XML was checkedRead the warnings: a missing import is the usual cause
Out of memoryThe file needed more than the 1 GiB limitValidate on a command line with xmllint --stream

Common xmllint error messages and fixes

libxml2's messages are precise but terse. These are the ones you'll meet most often, quoted as libxml2 prints them. The tool shows the same explanation next to each error it finds.

xmllint schema and parser messages with their meaning
MessageWhat it means
No matching global declaration available for the validation root.The root element's name or namespace isn't a top-level element in the schema; usually a missing or wrong xmlns
This element is not expected. Expected is ( quantity ).Wrong order or name: xs:sequence expects quantity at this point
Missing child element(s). Expected is ( qty ).A required child element is absent
'2026-13-01' is not a valid value of the atomic type 'xs:date'.The text doesn't fit the type; xs:date needs YYYY-MM-DD
[facet 'pattern'] The value 'ab' is not accepted by the pattern '[A-Z]{3}'.The whole value must match the regular expression
[facet 'enumeration'] The value 'c' is not an element of the set {'a', 'b'}.Only listed values are allowed, case-sensitive
The attribute 'cur' is required but missing.Add the attribute
The attribute 'foo' is not allowed.The attribute isn't declared for this element
Character content other than whitespace is not allowed because the content type is 'element-only'.Stray text inside an element that only holds child elements
Failed to locate a schema at location 'common.xsd'. Skipping the import.An imported schema wasn't supplied (a warning that causes later errors)
The QName value '{urn:c}T' does not resolve to a(n) type definition.A type is used but never defined, often because of a skipped import
parser error : Opening and ending tag mismatch: id line 2 and iddNot well-formed: the closing tag doesn't match
parser error : xmlParseEntityRef: no nameA bare & in text; write &

Names in curly brackets, such as {urn:example:invoice}line, are libxml2's way of writing an element together with its namespace. The tool splits them into the name and the namespace.

Example: "No matching global declaration available"

Load the valid example and delete xmlns="urn:example:invoice" from the root element. The tool warns before you run it, and libxml2 then reports a single error on line 2:

invoice.xml:2: Schemas validity error : Element 'invoice':
No matching global declaration available for the validation root.

Nothing else in the file is checked, because the validator never found a declaration to start from. The schema declares targetNamespace="urn:example:invoice", so its invoice element is {urn:example:invoice}invoice. An invoice element in no namespace is a different name. Put the xmlns back and the file validates. Because the schema also sets elementFormDefault="qualified", the child elements must be in that namespace too, which the default xmlns on the root takes care of.

The same error appears when the root is simply the wrong element, for example a <line> fragment checked on its own, since only top-level xs:element declarations can be a document root.

How imported and included schemas are found

Large schemas are split across files with xs:import (another namespace), xs:include (same namespace) and xs:redefine. The validator can't read your disk or the web, so add those files under Supporting schemas. Before validating, the tool reads every schemaLocation, matches it to an uploaded file by name and lists anything missing.

How each kind of schemaLocation is resolved
schemaLocationExampleWhat the tool does
File namecommon.xsdUses the uploaded file with that name
Relative pathlib/common.xsdPlaces the uploaded common.xsd at that path
Path upwards../base/base.xsdResolved from the file that references it, as libxml2 would
Web addresshttps://…/v2/common.xsdPoints the reference at your uploaded copy; nothing is downloaded
Not uploadedtypes.xsdListed in red before you validate

A missing xs:include stops the schema from compiling. A missing xs:import is only a warning ("Skipping the import"), but every type from that namespace is then undefined, so the errors appear later as "does not resolve to a(n) type definition". Files are matched by name only, so two different files that are both called common.xsd in different folders can't be used in the same run.

Why xsi:schemaLocation is ignored

Many XML files name their schema with xsi:schemaLocation or xsi:noNamespaceSchemaLocation. The XSD specification treats these as hints that a processor may ignore, and xmllint does when it is given a schema to use. This tool checks every file against the schema you paste or upload, whatever the hint says. That means a typo in the hint, or a hint that points to a web address, can't change the result. It also means you must load the right schema yourself.

XSD 1.0 only: what libxml2 supports

libxml2 implements XML Schema 1.0. Schemas written for XSD 1.1 fail to compile, usually with a confusing "The content is not valid" message, so the tool flags 1.1 features before you validate. These are the results from running each feature through the validator:

XSD features and libxml2 support
FeatureXSD versionlibxml2
xs:sequence, xs:choice, xs:all1.0Supported
Facets: pattern, enumeration, length, ranges1.0Supported
xs:key, xs:keyref, xs:unique1.0Supported
Substitution groups1.0Supported
xs:import, xs:include, xs:redefine1.0Supported
xs:assert, xs:assertion1.1Schema error
xs:alternative (conditional types)1.1Schema error
xs:openContent, xs:override1.1Schema error
xs:all with maxOccurs > 11.1Schema error

For XSD 1.1 schemas, use a 1.1 processor such as Saxon-EE or Apache Xerces-J with XSD 1.1 support.

Large files, encodings and privacy

The validator may use up to 1 GiB of memory. A 113 MB test file validated within that limit, where the old 64 MiB limit failed on a 24 MB one. Very large files are slow to edit in a text box, so upload them instead of pasting. If a file still runs out of memory, xmllint's --stream option on a command line validates without loading the whole document.

Uploaded files are decoded the way an XML parser reads them: a byte-order mark first, then the encoding in the XML declaration. UTF-8, UTF-16 and ISO-8859-1 or Windows-1252 files all display correctly. The text is then handed to libxml2 as UTF-8, with the declaration changed to match, so line numbers stay the same.

Files are processed in a Web Worker inside this page. Nothing is uploaded to a server, and the validator has no network access, so it can't fetch schemas or external entities.

Frequently asked questions

Does it use the schema named in xsi:schemaLocation?

No. Every file is checked against the schema loaded in the tool. The XSD specification treats xsi:schemaLocation as a hint, and xmllint ignores it when a schema is given.

Can it validate against XSD 1.1?

No. libxml2 supports XML Schema 1.0. Schemas using xs:assert, xs:alternative, xs:openContent or xs:override fail to compile, and the tool warns about them before you validate.

Can it download imported schemas from the web?

No. Download them yourself and add them under Supporting schemas. A schemaLocation that is a web address is pointed at the uploaded copy with the same file name.

Can I check several XML files at once?

Yes. Add them under "More XML files". Each file gets its own result, and errors show which file and line they come from.

Why does an error name the element as {urn:…}name?

That is the element name with its namespace in curly brackets. If the namespace isn't the one your schema expects, the element is a different element as far as the schema is concerned.

Are my files uploaded anywhere?

No. Validation runs in a Web Worker inside your browser, with no network access.

Sources