Validate XML Against XSD

: Validate an XML document against an XSD schema with libxml2, every error by line
EmptyLimits: 512 MB · .xml, .xsd or .txt
EmptyLimits: 512 MB · .xml, .xsd or .txt
Report
Paste an XML document and its XSD schema: libxml2 checks both in this tab.

Paste an XML file and the XSD it should follow, and every place where the document breaks the schema is listed by line. The check is libxml2, the library behind xmllint --schema, compiled to WebAssembly and running in this tab, so neither file is uploaded.

  1. Paste the document into the XML document pane and the schema into XSD schema, or press Open file on either pane (or drop a file on it) to read a file from your disk. Examples offers Valid example, an invoice and its schema that pass, and Invalid example, the same schema with a document that breaks it in four places.
  2. The check runs a moment after you stop typing. The engine starts loading with the page; if you are faster, a notice says Loading the libxml2 engine… until it is ready, which only takes a while on the first visit.
  3. Read the verdict at the top of the Report pane: Valid against the schema, Not valid with an error count, Not well-formed XML, or Schema errors, in which case the document was not checked at all.
  4. Click a finding to jump to its line: document errors select the line in XML document, schema errors the line in XSD schema.
  5. Press Copy for the whole report as plain text, or Download to save it.

A schema for an order, and a document with three mistakes: no id attribute, a word where a positive integer belongs, and an element the schema does not declare. Line numbers count from the top of the XML document; this is the text Copy gives.

Input
<!-- schema.xsd -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="order">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="sku" type="xs:string"/>
        <xs:element name="qty" type="xs:positiveInteger"/>
      </xs:sequence>
      <xs:attribute name="id" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
</xs:schema>

<!-- document.xml -->
<order>
  <sku>X-1</sku>
  <qty>two</qty>
  <gift>yes</gift>
</order>
Output
document is not valid against the schema — 3 errors
[x] line 1 — Element 'order': The attribute 'id' is required but missing.
[x] line 3 — Element 'qty': 'two' is not a valid value of the atomic type 'xs:positiveInteger'.
[x] line 4 — Element 'gift': This element is not expected.

Why does it say no matching global declaration for the validation root?

The document's root element is not declared at the top level of the schema, or it is in a different namespace. If the schema has targetNamespace="urn:x", the root needs xmlns="urn:x" (or a prefix bound to it), and the element has to be a direct child of xs:schema.

Why are there schema errors when I only wanted to check my XML?

libxml2 cannot validate against a schema it cannot compile, so a broken XSD stops the run. Fix the schema errors listed, or check the schema on its own with the XSD Validator.

Does it use the schema named in xsi:schemaLocation?

No. Nothing is fetched, so the only schema used is the one you paste or open in the XSD schema pane.

Runs entirely in your browser. Nothing is uploaded.