DataToolsLab
XML Tools

XML Schema Generator

Infer a basic XSD from one or more sample documents — element types, cardinality and attribute requiredness.

Loading tool…

What is Schema Generator?

A schema inference tool. Nobody enjoys writing the first version of an XSD by hand, and the first version is exactly the part the data already knows: which elements exist, what repeats, which attributes are always there.

How it works

Each sample document is absorbed into an inferred model. Element text is typed from the values — integer, decimal, boolean, date, dateTime or string — with enumerations emitted for short value sets when asked. Cardinality comes from comparing the samples: an element present in both is required, one present in only one becomes minOccurs=0, and maxOccurs is unbounded where it repeats. Attributes become required only when every instance carried them.

  1. Paste the document. Drop in XML, a schema, a feed or an XPath expression. Everything is parsed in the page: no upload, no server round trip, and the tools keep working with the network switched off.
  2. Set the options that match your document. Indent unit, whether to keep comments, which dialect, which output method. The defaults are the safe ones — nothing that changes meaning is enabled for you.
  3. Read the result, then copy or download it. Results appear as you type, copy straight to the clipboard, and download with a sensible filename (.xml, .xsd, .csv). Reset returns every field to its default.

Examples

A minified document from an API response

Paste one line of XML and the Formatter indents it, wraps long start tags one attribute per line and normalises empty elements — without touching text inside mixed content.

An XPath that works in Chrome and not in your servlet

The XPath Tester evaluates against a real tree and reports the axis or function it cannot support, instead of returning zero nodes and letting you guess why.

A document that will not parse

The Validator gives line and column for every mismatched tag, stray ampersand and duplicate attribute, with the reason in words: which open element was expected, which was found.

A schema that only half matches your data

The XSD Validator marks each violation with the path of the offending node, and the Schema Generator goes the other way — inferring a starting-point XSD from real documents.

Common mistakes

Assuming a pretty-printer cannot change meaning

Whitespace between elements is often insignificant, but inside mixed content it is not: `<p>Hello <b>world</b></p>` must stay on one line. Formatting here re-indents element-only content and leaves mixed content alone.

Treating a validation pass as proof of interoperability

The DTD and XSD validators implement honest subsets. A document reported valid here can still be rejected by a full validator that understands identity constraints, substitution groups or XSD 1.1 assertions — each page lists what it does not cover.

Reading the whole document because the parser did

A DOCTYPE is not inert. If your parser resolves external entities, pasting an untrusted document is enough to read a file or call an internal URL. The XXE Risk Checker shows what a document asks for; the fix is in the parser configuration.

Forgetting that attributes and elements are not interchangeable

`<id>1</id>` and `id="1"` mean different things to every schema and every XPath. When converting to CSV or YAML the distinction is preserved (`@id`), because flattening it away is the change that costs an afternoon later.

Frequently asked questions

Why does one sample document not produce a good schema?

Because a single instance cannot tell you what is optional. Every element it happens to contain looks mandatory, and every element it happens to omit is invisible. Two documents with realistic differences give a far better starting point for exactly this reason.

How accurate are the inferred types?

As accurate as the values you supply. Ten prices of 0.04 look like xs:decimal; one `free` among them makes the field a string, which is correct but looser than you wanted. Review the result — the tool is for writing the boring 80%, not for replacing judgement.

Should enumerations be generated?

For a status or category field with a handful of values, yes: it documents the vocabulary and catches typos. For free text, no — a schema that only accepts the twelve surnames that appeared in your samples will reject the thirteenth customer. The option is on by default and easy to turn off.

Online