How to Create an XSD from XML and Validate Files Against It
Generate an XML schema from sample files, refine types and rules, then validate XML against any XSD with line-by-line errors, all inside your browser.

How to Create an XSD from XML and Validate Files Against It
XML is far from dead. Bank statements, e-invoices, customs declarations, product feeds, medical messages and configuration exports still travel as XML, and each format is pinned down by an XML Schema, the XSD. Two situations come up again and again: you have sample files but no schema and need one, or you have a schema and a file that some system rejects without saying why. The free XSD Generator and XML Schema Validator handles both without uploading anything.
Part one: generating a schema from samples
Collect good samples
A schema inferred from one file describes only that file. If an element is optional, or sometimes repeats, the generator can only know if it sees a file where it is missing or repeated. Gather three to ten real documents that cover the variety you expect, and add them all.
Infer the model
Press Infer schema from samples. The tool walks every document, groups elements by their position in the tree, counts how many times each child appears inside its parent and merges the child order across files. Values are tested against the lexical rules of XSD types: true and false become boolean, whole numbers integer, numbers with a decimal point decimal, ISO dates date or dateTime, links anyURI, and everything else string. If the order of children varies between files, the group becomes a choice instead of a sequence. With Detect enumerations on, a text field that only takes a few repeated values, like a status, becomes a list of allowed values.
Review the guesses
Inference is a starting point, not a verdict. Open each element in the tree and ask whether the guess is right for every future file, not just your samples. Product codes and postcodes made of digits are the classic trap: 00731 looks like an integer, but an integer type would accept 731 and reject nothing useful, so set it to string with a pattern instead. Raise maxOccurs where a list could grow, set minOccurs to 0 where a field is optional by contract even if all samples have it, and add lengths and ranges where the receiving system has limits. Documentation text written here ends up in the schema as xs:documentation, which helps the next person.
Write the XSD
Choose the style. Nested, or Russian doll, keeps every definition inside its element and is easy to read. Named types, or Venetian blind, gives each complex element a reusable named type, which many code generators prefer. A target namespace from your samples is kept, with elementFormDefault set as you choose. Copy or download the .xsd, or send it straight to the validator.
Part two: validating XML
Load the schema
Paste or open any XSD 1.0 schema, your own or one published by a partner or a tax authority. The tool reports problems in the schema itself, such as a reference to a type that is not defined, and warns about imports and includes, which are not fetched. If a schema imports a small common types file, paste those declarations into the same schema.
Check a document
Paste or open the XML. Well-formedness comes first: an unclosed tag or a stray ampersand is reported with its line and column. Then the validator walks the document against the schema and lists every problem it finds, not just the first. Typical messages read like this:
- Required attribute id is missing on order, at /orders/order[2].
- Unexpected element note inside order; expected item or total.
- date: 2026-02-30: day 30 does not exist in that month.
- status: pending is not one of the allowed values: paid, new, shipped.
The first error line is highlighted in the editor, and the full list can be downloaded as text for a bug report.
Batch mode
When an integration rejects some files from a nightly export, use Batch validate files to check a whole set against the schema. The table lists each file with its number of errors and the first problem, so you can see at a glance whether one bad record or a systematic change caused the failures.
Part three: documentation
The Documentation tab turns any loaded schema into a reference table: every element and attribute reachable from the root with its path, type, occurrence range, rules such as allowed values and patterns, and the description text. Print it as a PDF for a partner, or download HTML or Markdown for a wiki.
Limits worth knowing
The validator covers what most exchange formats use: elements, attributes, sequences, choices, all groups, wildcards, groups and attribute groups, simple and complex content with extension and restriction, every built-in type and facet, lists, unions, nillable elements, IDs and namespaces. It does not check key and keyref constraints, substitution groups, xsi:type or XSD 1.1 assertions, and it does not fetch imported files. For final certification of a regulated format, run the official validator as well; for everyday debugging, this is usually the quickest way to the answer.



