xmltoolskit.org
XML utilities, in the browser
Say hi →

XML to XSD

updated 26 August 2026

xml → xsd
Drop a .xml file here, or
ready

XML to XSD

Paste a representative document and get a schema that validates it. This is the mirror of XSD to sample XML, and the honest framing is that it is a starting point: one sample cannot tell you the full contract, so the tool is explicit about which parts it observed and which it assumed. Read the status line — it counts what was inferred.

What can and cannot be inferred from one document

A schema states what is allowed. A document only shows what occurred. Everything interesting about generating one from the other lives in that gap, so here is exactly which way each guess is made:

Nested or flat

Nested uses anonymous inline types, so the schema reads in the same shape as the document. It is the easier one to check against a sample by eye, and the right default.

Flat declares every element globally and refers to them by ref. That is the shape you want if the schema will be maintained by hand or imported elsewhere, because each element is defined exactly once — but it also means two elements that happen to share a name must share a definition, so their models are merged.

Either way, an element name that appears in several places is modelled once from every occurrence combined. If your document uses <item> for two genuinely different things, the inferred type is the union of both and will be looser than either. Rename one, or split the schema.

Namespaces

If the sample's root is in a namespace, that becomes the targetNamespace and elementFormDefault="qualified" is set, which is what makes an unprefixed child element in your document validate. A document in no namespace produces a no-namespace schema. Multiple namespaces in one document are beyond what a single inferred schema can express — the first is used and the rest are kept as literal prefixed names, which will need an xs:import adding by hand.

FAQ

Can I trust the output as-is?

Only as far as your sample is representative. Validate a few other real documents against it with the XSD validator — that is the fastest way to find where the sample was too narrow, and it is a two-minute check that saves a bad schema from shipping.

Why xs:all rather than xs:choice when the order varies?

Because varying order is evidence about ordering, not about alternation. xs:choice says exactly one of these appears, which is a much stronger claim and one a sample showing several children together actually contradicts. xs:all says these appear, in any order — which is precisely what was observed.

Does it handle comments, CDATA and processing instructions?

Comments and processing instructions carry no schema information and are ignored. CDATA is treated as text, which is what it is — so an element whose value arrives in a CDATA section is typed from that text like any other.

Is my document uploaded?

No. Parsing uses the browser's own XML parser and the schema is built in the page. Nothing is sent anywhere.