How to use
- Paste the XML into the input box. It starts with a sample.
- If the syntax is wrong, you get the line and column and the reason, with the surrounding lines highlighted.
- If the syntax is fine, you get a summary: element count, attribute count, depth, namespaces and per-element counts.
- 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), namedsimpleType,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 attributememo, 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 beid="1". - A bare
&: write&. A URL such as?a=1&b=2is a frequent cause. A literal<is written<. - 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.