Skip to content

XML to XSD Generator

Infer an XML Schema (XSD) from sample XML: nesting, element order, optional and repeated elements, attributes and simple types.

Runs in your browserXML → XSD
Loading tool…

Example

Input
<library><book id="1" lang="en"><title>Dune</title><published>1965-08-01</published><price>9.99</price></book><book id="2"><title>Emma</title><published>1815-12-23</published></book></library>
Output
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
  <xs:element name="library">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="book" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="title" type="xs:string"/>
              <xs:element name="published" type="xs:date"/>
              <xs:element name="price" type="xs:decimal" minOccurs="0"/>
            </xs:sequence>
            <xs:attribute name="id" type="xs:integer" use="required"/>
            <xs:attribute name="lang" type="xs:string"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

How to use the XML to XSD Generator

  1. Paste a representative XML sample. The more complete the sample (all optional elements and attributes present somewhere), the better the schema.
  2. Elements missing from some instances get minOccurs="0"; elements repeated inside one parent get maxOccurs="unbounded"; attributes present on every instance are use="required".
  3. Review the result: the schema describes your sample and may need loosening (e.g. xs:string instead of xs:integer) before you use it to validate other documents.

Privacy and limitations

  • Your data is processed on your device and is not uploaded to any server.
  • Uses nested anonymous types ("Russian doll" design); elements with the same name in different places get separate definitions.
  • Only the root element’s namespace becomes the targetNamespace; elements from other namespaces and namespaced attributes (other than xmlns and xsi:*) are not modelled.
  • Enumerations, patterns, lengths and numeric ranges are not inferred.

Frequently asked questions

How are types chosen?

Each element and attribute gets the narrowest type that fits every sampled value: xs:boolean (true/false), xs:integer, xs:decimal, xs:date, xs:dateTime, otherwise xs:string. Values with leading zeros such as 007 stay xs:string, and elements that are empty in some instances are xs:string.

When is xs:choice used instead of xs:sequence?

If children appear in different orders or interleaved (e.g. a, b, a), a fixed sequence cannot describe them, so the children are wrapped in an unbounded xs:choice.

Browse all xml converters →