Monitoring
Solutions
Resources
Free Tools
Pricing
Free Tools / Converters / XML to XSD Generator

XML to XSD Generator

Paste a sample XML document and get an XSD that describes it: the nesting, the attributes, which elements repeat or may be missing, and a data type for every value.

Runs entirely in your browser — nothing you enter here is sent to a server.

What the generator infers

An XML Schema (XSD) is a contract: it states which elements and attributes a document may contain, in what order, how often, and what type each value has. Writing one by hand is tedious. This generator reads a sample document and writes the schema that the sample satisfies — a starting point you then tighten.

Structure

Each element with children or attributes becomes a complexType with a sequence, nested where it is used (the "Russian doll" style).

Repetition

An element that appears more than once under the same parent gets maxOccurs="unbounded".

Optional parts

An element missing from some instances gets minOccurs="0"; an attribute present on every instance gets use="required".

Data types

Values are checked against xs:boolean, xs:integer, xs:decimal, xs:date and xs:dateTime, falling back to xs:string.

Why the sample matters

The schema can only be as good as the example. Everything is inferred from what is present, so give the generator a document that shows the variety: at least two instances of anything that repeats, one instance with the optional elements and one without. A sample with a single order cannot reveal that orders repeat, and a sample in which every order has a gift flag will make that flag mandatory.

Review the result before using it as a contract. Typical edits: replace xs:string with an enumeration where only a few values are allowed, add length or pattern restrictions, relax xs:sequence if element order should not matter, and move repeated structures into named types if several parts of the schema share them.

Frequently asked questions

What is an XSD?

An XML Schema Definition: an XML document that describes the allowed structure and data types of other XML documents, so that they can be validated automatically.

How accurate is a generated schema?

It is exactly as permissive as the sample requires. Anything the sample does not show — an optional element, a second occurrence, an alternative value type — is not in the schema, so use a representative sample and review the result.

How do I validate XML against the XSD?

With any validating parser. On the command line: xmllint --noout --schema schema.xsd document.xml. Most IDEs and XML libraries can validate as well.

Does the generator handle namespaces?

If the root element has a default namespace, it is set as the schema's targetNamespace. Documents that mix several namespaces need one schema per namespace and should be finished by hand.

Related free tools

A calculator answers once. Monitoring answers every minute.

Upzilla checks your sites, servers and APIs around the clock and alerts you the moment something breaks. 10 monitors free, no card required.

Start monitoring free →