XML to XSD Generator

: Infer an XML Schema from a sample XML document
Limits: 50 MB · .xml or plain text · An inferred starting point: review types, required fields and occurrence limits against other documents. Large files are read with a progress line and can be cancelled; nesting is limited to 64 levels. DTDs and custom entities are rejected.
XSD
The inferred schema appears here as you type.

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.

  1. Paste an XML document into the Sample XML pane, press Open file to select a file, or press Example to load an orders example.
  2. The XSD appears as you type; a document over 2,000,000 characters waits for the Generate button instead and shows its progress, with Cancel. Parse errors or unsupported namespace features appear in a message above the panes.
  3. Read the XSD pane and the warnings above it, especially any warning about child order. Press Copy or Download to save the result.
  4. Check more documents with the XML Validator (XSD), then adjust the schema's types and occurrence limits as needed.

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.

Input
<order><line code="001"><quantity>2</quantity><note>Gift wrap</note></line><line code="002"><quantity>1</quantity></line></order>
Output
<?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>

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.