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
<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>
<?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
- Paste a representative XML sample. The more complete the sample (all optional elements and attributes present somewhere), the better the schema.
- Elements missing from some instances get minOccurs="0"; elements repeated inside one parent get maxOccurs="unbounded"; attributes present on every instance are use="required".
- 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.
Related converters
XML FormatterBeautify and indent XML while keeping comments, CDATA sections, attributes and element order exactly as written.XML ValidatorCheck that XML is well-formed: matching tags, quoted attributes and a single root, with line numbers.JSON to JSON SchemaInfer a draft 2020-12 JSON Schema from a sample JSON document.XPath TesterRun XPath 1.0 expressions against an XML document and see the matching elements, attributes or values.XML to HTML TableTurn repeated XML elements into an HTML table with a header row, with a safe live preview.XML to CSV ConverterConvert repeated XML records into CSV rows. Child elements and attributes become columns.XML to YAML ConverterConvert XML documents to readable YAML, keeping attributes as @_name keys and repeated elements as lists.XML to JSON ConverterConvert XML to JSON. Attributes become @_name keys, repeated elements become arrays, numbers are detected.