Paste one or more sample XML documents and get an XML Schema (XSD 1.0) that describes them: element structure, data types such as xs:int, xs:decimal and xs:date, which elements are optional or repeated, attributes and their required status, and the target namespace. Choose Russian doll, Salami slice or Venetian blind layout.
Last updated:
Several samples of the same format give a better schema: elements missing from some samples become optional and repeated ones get maxOccurs="unbounded".
Inferred structure
Element
Type / content
Occurs
Attributes
Everything is generated in your browser; your XML is never uploaded. Review the result: a schema inferred from samples only knows the values it has seen.
Advertisement
Advertisement
How to use the XML to XSD Generator
Paste a sample XML into the left box, open one or more .xml files, or load the two book catalog samples.
Add more samples with + Add sample: the more real documents you give, the more accurate the optional and repeated elements are.
Pick a schema design and options such as type detection, enumerations and annotations.
Review the XSD and the Inferred structure table; adjust types or occurrences that your samples could not reveal.
Copy or download the schema as an .xsd file.
How sample values map to XSD built-in types
Values seen
Inferred type
Notes
true, false
xs:boolean
XSD also allows 1 and 0, but those are typed as numbers to avoid false matches.
42, -7
xs:int
Within ±2,147,483,647; larger values become xs:long, then xs:integer.
44.95, .5
xs:decimal
Exact decimal, ideal for prices and quantities.
1.5E3, INF
xs:double
Used when values contain an exponent or special values.
2024-05-01
xs:date
ISO 8601 date, optional time zone.
2024-05-01T09:30:00Z
xs:dateTime
Date and time with optional fraction and time zone.
14:30:00
xs:time
Seconds are required by the XSD lexical form.
P3DT4H
xs:duration
ISO 8601 durations.
https://…, mailto:…
xs:anyURI
Only when every value starts with a URI scheme.
00123, mixed or empty values
xs:string
Leading zeros and empty instances keep the type permissive.
Using the generated XSD
Reference it from XML: declare the xmlns:xsi prefix for the XML Schema instance namespace (http://www.w3.org/2001/XMLSchema-instance) on the root element, then point to the file with the xsi:noNamespaceSchemaLocation attribute (value: catalog.xsd) when there is no namespace, or with xsi:schemaLocation (value: the namespace, a space, then catalog.xsd) when there is one.
Tighten it: add maxLength, pattern or minInclusive facets, and turn small fixed value sets into enumerations (the Detect enumerations option suggests them).
Generate code: the Venetian blind layout produces named types that map cleanly to classes in JAXB (xjc), .NET (xsd.exe) and similar tools.
Validate documents against the schema with xmllint (xmllint --noout --schema catalog.xsdfile.xml) or your IDE; tidy the sample files first with the XML Formatter.
Working with JSON instead? The JSON Schema Generator does the same job for JSON documents.
Frequently asked questions
How does the generator decide the data type of a value?
It looks at every value an element or attribute has across all samples. If all are true/false it uses xs:boolean; if all are whole numbers, xs:int (or xs:long/xs:integer for large values); decimals become xs:decimal; ISO 8601 values become xs:date, xs:dateTime or xs:time; URLs become xs:anyURI. Anything else, or a mix, is xs:string.
Why is a number like 00123 typed as a string?
Leading zeros usually mean an identifier (ZIP code, account or product number) rather than a quantity. Typing it as an integer would make a validator accept 123 and lose the zeros in many tools, so such values stay xs:string.
How are minOccurs and maxOccurs calculated?
For each parent element, the tool counts how often each child appears in every instance. A child missing from at least one instance gets minOccurs="0"; a child that appears more than once in any instance gets maxOccurs="unbounded". Defaults (1) are not written out.
What is the difference between Russian doll, Salami slice and Venetian blind?
Russian doll nests every declaration inside its parent, giving one compact global element. Salami slice declares every element globally and links them with ref, which makes elements reusable. Venetian blind declares named complex types (bookType, catalogType) and uses local elements, which suits code generators like JAXB and xsd.exe.
Can I trust the generated schema as-is?
Treat it as a strong first draft. It only knows what the samples contain: an element that is optional but present in all your samples will be marked required, and a field that happened to contain only numbers will be typed as a number. Review the types and occurrences before using the schema for validation.
Does it support namespaces?
Yes. The root element's namespace becomes the targetNamespace with elementFormDefault="qualified". Elements from other namespaces are allowed through xs:any, and xml:lang style attributes are referenced from the standard XML namespace schema.
Is my XML uploaded?
No. The XML is parsed with your browser's built-in DOMParser and the schema is generated locally. Your files never leave your device.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.