1. Home
  2. Developer
  3. XML Validator

XML Validator

Locate XML syntax errors and validate structure against an XSD.

For every format and option in one place, use Code Formatter and Checker →

Runs in your browser · No upload

Fix the XML syntax errors first to run the XSD check.

The XSD check supports common features only (element order and occurrences, attributes, built-in types, enumeration, pattern, length and range facets). Namespaces are ignored and names are compared without prefixes. It does not replace a full XSD 1.0 validator.

Your XML and XSD are checked in this browser and never uploaded.

How to use

  1. Paste the XML into the input box. It starts with a sample.
  2. If the syntax is wrong, you get the line and column and the reason, with the surrounding lines highlighted.
  3. If the syntax is fine, you get a summary: element count, attribute count, depth, namespaces and per-element counts.
  4. To check against an XSD schema, turn on Also validate against an XSD schema and paste it. Element order, occurrences, required attributes and value types are checked and the findings are listed in a table.

Two kinds of checks

Check What it verifies Needs
Syntax (well-formed) Tags pair up, one root element, attribute values are quoted, entities and name rules XML only
Schema (valid) The document follows the structure and type rules of an XSD XML and XSD

The syntax check is decided by the browser’s XML parser (DOMParser). This tool extracts the line and column from its message and explains the cause. When the syntax has errors the XSD check is skipped, because a document must be well-formed before it can be compared with a schema.

What the XSD check supports

  • Elements: global and local element, ref, sequence, choice, all, group, any, minOccurs, maxOccurs
  • Types: complexType (extension, restriction, simpleContent, mixed), named simpleType, list, union
  • Attributes: attribute, attributeGroup, use (required, optional, prohibited), fixed
  • Facets: enumeration, pattern, length, minLength, maxLength, minInclusive, maxInclusive, minExclusive, maxExclusive, totalDigits, fractionDigits
  • Built-in types: the string family, boolean, the integer family (with ranges for int, long, positiveInteger and so on), decimal, float, double, date, dateTime, time, duration, gYear, language, NCName, hexBinary and more

key, keyref, unique, substitutionGroup, import and include are not supported and are skipped; skipped features are listed under the result. Namespaces are ignored and names are compared without prefixes, so a document with same-named elements in different namespaces cannot be told apart exactly.

Sample result

With the sample XML and XSD in the boxes, the syntax passes and there are 2 schema violations:

  • Line 2: <order> has the attribute memo, which the XSD does not declare
  • Line 6: the value “0” of <qty> is not a positiveInteger (an integer of 1 or more)

Common causes of violations are an element without maxOccurs appearing more than once (the default is exactly one) and optional elements missing minOccurs="0".

Common syntax errors

  • Opening and closing tag names differ: names are case-sensitive. <Item></item> is an error.
  • Unquoted attribute value: unlike HTML, XML does not allow id=1. It must be id="1".
  • A bare &: write &amp;. A URL such as ?a=1&b=2 is a frequent cause. A literal < is written &lt;.
  • More than one root element: a document has a single top-level element.
  • Whitespace before the XML declaration: <?xml ... ?> must be the very first thing in the document.

Frequently asked questions

What is the difference between well-formed and valid?

Well-formed means the XML syntax is followed. Valid additionally means the rules of a schema such as a DTD or XSD are followed. A document can be well-formed and still not match its schema.

How do I create an XSD?

If writing one by hand is a chore, put a sample XML into the XSD Generator for a first draft, paste it here, and tighten it yourself with enumerations or required attributes.

Why do I only see one syntax error at a time?

The parser stops at the first syntax error. Fix it and check again to see the next one. XSD violations are shown up to 100 at once.

Does it check the encoding of an XML file?

No. The tool checks the text you paste, not the actual bytes of a file. If the declared encoding is not UTF-8 you get an informational note.

Related tools: XML Formatter, XSD Generator, XML to CSV Converter, HTML Validator, JSON Formatter.

Your XML and XSD are checked in your browser and never sent to a server.

Can't find the tool you need?

Tell us what you want to do. We build the most requested tools first.