Generate XSD from XML

Infer elements, attributes and data types from one or more XML documents — 100% in your browser, no upload, free forever.

One sample infers the structure. Two or more samples also detect optional elements (minOccurs="0"), optional attributes and value types that change between documents.

All types are nested inside the root element.

Advanced options

Generated XSD

How to generate an XSD from XML

To convert XML to XSD, paste or drop a document — this XSD schema generator infers the schema from the element structure in seconds, so you never write it by hand. You can generate a schema from XML on any device, with no install and no upload.

  1. Add your XML — paste or drop a document. Add more samples of the same structure to infer optional fields; every document is parsed locally in your browser and never leaves your device.
  2. Pick the output style — Single file inlines every type, while Separate types emits named complexType definitions.
  3. Generate and export — copy the schema or download it as a .xsd file, ready for validators and code generators.

Why generate schemas locally

This XML to XSD generator runs entirely in your browser, so there is no file size limit imposed by a server, no signup, and your data is never uploaded or stored. It works offline after the page is loaded, and the same engine runs on Windows, macOS and Linux.

The inferred schema captures element order, repeated elements (maxOccurs="unbounded"), attributes, namespaces and simple types such as integer, decimal, boolean, date and dateTime. Mixed or unknown content is emitted as xs:anyType so the result stays valid. Feed the generator several representative samples and it will also detect optional elements (minOccurs="0") and optional attributes, and explain every decision in a diagnostics panel below the result.

Example: XML in, XSD out

This is the kind of document the generator handles best — a namespace declaration, nested elements, repeated elements, and an attribute. Paste it into the box above and press Generate XSD to see the live result.

<?xml version="1.0" encoding="UTF-8"?>
<order:orders xmlns:order="https://example.com/order">
  <order:order id="1001">
    <order:customer>Ada Lovelace</order:customer>
    <order:shipped>false</order:shipped>
    <order:item>
      <order:sku>BOOK-001</order:sku>
      <order:qty>2</order:qty>
      <order:price>19.95</order:price>
    </order:item>
    <order:item>
      <order:sku>PEN-014</order:sku>
      <order:qty>5</order:qty>
      <order:price>1.20</order:price>
    </order:item>
  </order:order>
</order:orders>

order:orders is a QName: prefix order, namespace URI https://example.com/order, local name orders. XSD element declarations must use local names (the name attribute is an NCName and cannot contain :), so the generator records the URI once in targetNamespace and emits unprefixed names. The repeated item element gets maxOccurs="unbounded", and xs:string, xs:boolean, xs:integer and xs:decimal are inferred from the sample values:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  targetNamespace="https://example.com/order"
  elementFormDefault="qualified">
  <xs:element name="orders">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="order">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="customer" type="xs:string"/>
              <xs:element name="shipped" type="xs:boolean"/>
              <xs:element name="item" maxOccurs="unbounded">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element name="sku" type="xs:string"/>
                    <xs:element name="qty" type="xs:integer"/>
                    <xs:element name="price" type="xs:decimal"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="id" type="xs:string" use="required"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Generate XSD from multiple XML samples

A single sample cannot prove a field is optional. Paste two orders into separate sample boxes — the second one without shipped and with an integer price — and press Generate XSD. The generator merges the structure across samples:

<order:order id="1001">
  <order:shipped>false</order:shipped>
  <order:price>19.95</order:price>
</order:order>

<order:order id="1002">
  <order:price>20</order:price>
</order:order>

The merged result marks shipped as minOccurs="0" (missing from one instance) and promotes price from xs:integer to xs:decimal (both forms appear). The diagnostics panel under the output shows exactly why:

XML → XSD with namespaces

In XML, <order:orders xmlns:order="https://example.com/order"> is a QName with three parts: the prefix order, the namespace URI https://example.com/order, and the local name orders. XSD does not keep prefixes in declarations — xs:element name values are NCNames, so a colon there is invalid. The generator maps the input's prefixes and URIs into the two schema mechanisms that actually carry namespaces:

You can override the inferred namespace in the Advanced options: set targetNamespace to your own URI. If it differs from the input's namespace, the generator warns that the result will no longer validate the original document.

XSD generator options explained

Common errors when generating XSD from XML

Frequently asked questions

What is an XSD?

An XSD (XML Schema Definition) describes the structure, order and data types of an XML document. It is the modern replacement for DTDs and is what validators and code generators use to check or consume XML.

Why should I provide several XML samples?

A single sample cannot prove a field is optional. Provide two or more samples and the generator detects elements missing in some instances (minOccurs="0"), attributes that are not always present (use="optional"), and value types that change between samples. The diagnostics panel under the output explains each decision.

What is the difference between an XML schema and a DTD?

A DTD is the older, simpler grammar with limited types and no namespace support. An XSD is written in XML itself and adds data types, namespaces and precise cardinality, which is why it is the standard choice today.

How is this different from the old xsd.exe command line tool?

xsd.exe ships with Visual Studio, runs on Windows only, and is not always installed in newer Visual Studio versions. This generator runs in any browser on Windows, macOS or Linux with no install; the same controls are exposed as on-page options.