How to use
- Paste sample XML into the input box. It starts with an orders example.
- Choose the prefix (
xs:orxsd:), indentation, type inference and enumeration options. - Copy the XSD draft below or save it with Download .xsd.
- To check that the generated XSD accepts your XML, paste both into the XML Validator.
The more times an element repeats in the sample, the better the repeat, optional and type guesses. With a single record every element looks like it appears exactly once.
What is read from the sample
| Observation | How it is written in XSD |
|---|---|
| Order of child elements | Listed in that order inside xs:sequence |
| Same element 2 or more times in one parent | maxOccurs="unbounded" |
| Element missing from some parents | minOccurs="0" |
| Attribute present on every instance | use="required" |
| Attribute on only some instances | Optional attribute (the default) |
| Element with text only | type="xs:string" or another inferred built-in type |
| Element with text and attributes | xs:simpleContent with xs:extension |
| Element mixing children and text | mixed="true" |
| Order differs between instances, or an element reappears after another | xs:choice minOccurs="0" maxOccurs="unbounded" |
minOccurs stays at 1 (the default) even when the sample always shows 2 or more. Forcing three because the sample happened to have three would make the rule too narrow.
Type inference
The most specific type that accepts every value is chosen.
| Example values | Inferred type |
|---|---|
1, -3, 2000 |
xs:int |
3000000000 |
xs:long |
3500 mixed with 1200.5 |
xs:decimal |
true, false |
xs:boolean |
2026-10-01 |
xs:date |
2026-10-01T09:30:00Z |
xs:dateTime |
10:30:00 |
xs:time |
007 (leading zero), an empty value, anything else |
xs:string |
Only 1 and 0 is treated as int, not boolean. Values with leading zeros (postal codes, codes) stay string because converting them to numbers would change them. With inference off every value is xs:string.
Sample result
The sample in the box (2 orders, 3 items) produces this structure:
orderrepeats insideorders(maxOccurs="unbounded")orderholdscustomer,status, an optionalmemo(minOccurs="0") and a repeatingitem- In
item,pricemixes3500and1200.5so it isxs:decimal, andqtyisxs:int - The attributes
id(xs:int),date(xs:date) andsku(xs:string) are all required
That is 9 element declarations and 3 attribute declarations.
The enumeration option
When on, string elements and attributes that have at least 3 samples, at most 5 distinct values, and at least one repeated value become xs:enumeration. For example a size attribute seen as S, M, S, M allows only S and M. The sample might simply not show other values, so this is off by default; check the result after turning it on.
Limits
- Rules the sample does not show cannot be generated. Add length limits, patterns and ranges yourself.
- Prefixed elements and attributes are written with their local names and namespaces are not reflected. If the root has a default
xmlns, onlytargetNamespaceandelementFormDefault="qualified"are added. - Every element is declared in place (nested style). Reusable named types are not generated.
Frequently asked questions
Can an XSD be generated from XML automatically?
A draft can, from the structure and values in the sample. Rules the sample does not show are unknown, so it is safest to edit the draft to match your real data rules.
What is the difference between the xs and xsd prefixes?
None in meaning. They are just names bound to the same namespace (http://www.w3.org/2001/XMLSchema), so pick whichever matches your team’s convention.
What if element order does not matter in my XML?
When order differs between instances the tool writes an xs:choice with no order constraint instead of xs:sequence. It cannot express per-element counts there, so switch to xs:all by hand if you need that.
Does the generated XSD accept the original XML?
In this tool’s tests, validating the original XML against the generated XSD passes. Whether data that differs from the sample passes is something to check yourself.
Related tools: XML Validator, XML Formatter, XML to CSV Converter, JSON to TypeScript, JSON Formatter.
Your XML is processed in your browser and never sent to a server.