XML to XSD Generator
: Infer an XML Schema from a sample XML documentXML to XSD Generator
Generate an XSD from XML when you have example data but no schema. This XML to XSD converter runs in your browser on Windows, Mac, Linux or ChromeOS, so the document is never uploaded. The generator compares repeated elements within that document to infer shared types, optional children and attributes. The result describes what was observed, so review it before treating it as a contract for future documents.
How to generate XSD from XML
- Paste an XML document into the
Sample XMLpane, pressOpen fileto select a file, or pressExampleto load an orders example. - The XSD appears as you type; a document over 2,000,000 characters waits for the
Generatebutton instead and shows its progress, withCancel. Parse errors or unsupported namespace features appear in a message above the panes. - Read the
XSDpane and the warnings above it, especially any warning about child order. PressCopyorDownloadto save the result. - Check more documents with the XML Validator (XSD), then adjust the schema's types and occurrence limits as needed.
Example
Two line elements show that note is optional. Quantity is an integer, while a leading-zero code remains a string; repeated line elements permit an unbounded number of occurrences.
<order><line code="001"><quantity>2</quantity><note>Gift wrap</note></line><line code="002"><quantity>1</quantity></line></order><?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="line" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="quantity" type="xs:integer"/>
<xs:element name="note" minOccurs="0" type="xs:string"/>
</xs:sequence>
<xs:attribute name="code" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>Details
- Literal
trueandfalseinferxs:boolean. Canonical whole numbers inferxs:integer, and a mixture of whole numbers and decimal notation infersxs:decimal. Leading zeros, dates, empty values, whitespace around values and conflicting types producexs:string. - Child elements are compared by namespace and local name at the same parent path. A child missing from one observed parent becomes optional (
minOccurs="0"). A child that repeats getsmaxOccurs="unbounded"but is required only once, however many times the sample repeats it. An attribute is required only when every observed instance of its element has it. A single document cannot show every legitimate omission. - The sequence follows the observed ordering constraints, including fields absent from some instances. Interleaved names or contradictory orderings produce a repeating
xs:choiceinstead, with a warning: this accepts more arrangements and weakens required-field constraints. - A root namespace becomes the schema's target namespace. Unqualified children use
form="unqualified". Text mixed with child elements producesmixed="true"; text positions and values are not restricted. Text-only elements with attributes use simpleContent.
Limits
- One input document per generation. Repeated elements provide multiple observations; there is no multi-file merge or schema editor on this page. The output is rebuilt on every change of the input up to 2,000,000 characters.
- Large files work: the document is read once and only its distinct element shapes are kept, so hundreds of thousands of elements give the same schema as one of each shape. Opened files can be up to 50 MB, and nesting is limited to 64 levels. DTDs and custom entities are rejected; predefined XML entities and numeric character references work.
- Multiple element namespaces require separate schemas and imports, which this generator does not create. Namespaced attributes, including
xml:langandxsi:nil, are rejected. The schema-location hintsxsi:schemaLocationandxsi:noNamespaceSchemaLocationare ignored with a warning, since validators accept them without a declaration. - Inference does not discover business rules, enumerations, keys, date formats or maximum repetition counts. Review the generated XSD 1.0 before relying on it.
FAQ
Can I use this as an XSD builder?
Use it to generate a starting schema from XML, then copy or download the XSD and edit it in your own text editor. This page has no visual schema editor or controls for changing the inferred declarations.
Why is my numeric identifier a string?
A value such as 001 keeps its leading zeros by becoming a string. Numeric inference only accepts canonical integer or decimal notation; scientific notation and surrounding whitespace also remain strings.
How do I create an XSD from an XML file?
Press Open file and choose the .xml file (or paste its text), then press Download to save the XSD. Use a file that contains every optional element and attribute at least once, and several instances of repeating elements, because the schema can only describe what the sample shows.
Can I go the other way, from XSD to XML?
Yes, with the XSD to XML tool on this site, which builds a sample document from a schema. To check other XML files against the generated schema, use the XML Validator (XSD).
Why did the generator use a choice instead of a sequence?
The sample has incompatible child orders or a name that returns after another child, such as a, b, a. A repeating choice can accept that input, but permits additional arrangements. The warning asks you to review the inferred model.
Runs entirely in your browser. Nothing is uploaded.