XML to XSD Converter
Paste or upload an XML file and get a working XSD schema back. This tool reads the structure of your document and works out elements, attributes, data types and repeat rules on its own, entirely in your browser.
Generated XSD
Reusable complex types, one per distinct element name.
Ready when you are
Paste XML on the left, or load the sample, then press Generate XSD schema.
Turn any XML document into a working XSD schema
Most XSD generators either need you to install desktop software or only handle trivial documents. This one walks your full XML tree, merges repeated tags into a single reusable type, and works out data types and occurrence rules from the values it actually finds, so the schema matches your real data instead of a generic template.
XML Schema Definition (XSD 1.0) output
What makes this XSD generator different
Built around how real XML documents are structured, not a toy example.
Accurate occurrence rules
Repeated sibling tags become maxOccurs="unbounded" automatically. A field missing from even one record is marked minOccurs="0", so the schema fits documents with optional fields.
Five inferred data types
Leaf text and attribute values are checked against xs:integer, xs:decimal, xs:boolean, xs:date and xs:dateTime, falling back to xs:string whenever a value does not fit cleanly.
Reusable complex types
Every distinct element name gets one named complex type, referenced wherever it appears again. Recursive tags, like a nested folder structure, reuse the same type instead of breaking the generator.
Optional target namespace
Add a namespace URI and choose qualified or unqualified elements, or leave it blank for a plain schema with no namespace at all.
Attributes handled properly
Attributes present on every instance of an element become use="required"; anything seen on only some instances becomes use="optional", each with its own inferred type.
Nothing leaves your browser
Parsing, inference and schema generation all run client-side in JavaScript. Your XML is never uploaded anywhere, which matters for internal configs and data with real customer values.
How the type inference works
A quick reference for what you will see in the generated schema and why.
| XML pattern | What the tool checks | XSD result |
|---|---|---|
| Same tag appears twice under one parent | Counts the highest number of siblings seen anywhere | maxOccurs="unbounded" |
| A child tag is missing from one record | Checks if the tag appears under every parent instance | minOccurs="0" |
| Text is always whole numbers | Tests every sampled value against an integer pattern | xs:integer |
| Text mixes whole numbers and decimals | Every integer is also a valid decimal | xs:decimal |
| Text mixes numbers and words | No single pattern matches every sampled value | xs:string (safe fallback) |
| An element contains other elements | Builds a named, reusable complex type | xs:complexType with xs:sequence |
| An element has a namespace prefix | Prefix is stripped before analysis | Local element name only |
The tool samples up to 200 values per field, which is more than enough to spot the pattern in typical documents.
What this tool does not do
Being upfront about the edges, since a schema inferred from one example is a starting point, not a certified spec.
- It does not resolve namespace URIs into separate schemas; every prefix is stripped, and the output describes local element names only.
- Mixed content (text sitting next to child elements) is marked mixed="true" but is not modeled field by field.
- It infers rules from the sample you provide. A field that happens to be a number in your sample, but could be text elsewhere, will be typed as a number here.
- It generates XSD 1.0 syntax, which is what almost every XML tool and validator still expects.
How this XML to XSD Converter works
This tool reads your XML in the browser and works out a matching XSD schema. It walks every element, groups the ones that share a tag name wherever they appear, then checks how often each tag shows up as a sibling. If a parent ever contains more than one, the schema marks it maxOccurs="unbounded". If the tag appears under every instance of its parent, minOccurs stays at 1; otherwise it drops to 0, so the schema still accepts documents where that field is missing.
Attribute and text values get the same treatment. The tool samples the values found for each attribute and each piece of leaf text, then tests them against patterns for integers, decimals, booleans, dates and date-times. When every sample matches one pattern, that becomes the XSD type. When the values disagree, it falls back to xs:string, so the schema never rejects real data over one odd row.
Elements that contain other elements get their own named complex type, reused everywhere that tag reappears. That reuse is also what stops a recursive structure, such as a folder tree built from nested node tags, from producing a schema with no end.
Namespace prefixes are stripped before analysis, because guessing the right namespace-aware structure from a single sample document is unreliable. Nothing you paste or upload leaves your browser; the XML is parsed and discarded the moment the schema appears on screen.
How to use this XML to XSD Converter
Paste or upload your XML
Drop in an .xml file or paste the markup directly. A sample catalog is loaded by default so you can see the tool in action first.
Set the schema options (optional)
Add a target namespace if your schema needs one, and choose whether new elements are qualified or unqualified. Leave both blank for a plain schema with no namespace.
Generate the schema
The tool walks the whole document, merges repeated tags, and infers minOccurs, maxOccurs and data types for every element and attribute.
Copy or download the XSD
Copy the schema to your clipboard or download it as a .xsd file, then validate your original XML against it in your editor or pipeline.
Example Usage
The <price> attribute becomes xs:decimal, and <inStock> is minOccurs="0" because only one of the two books has it:
Frequently Asked Questions
What is an XSD schema, and why would I generate one from an XML file?
How does the tool decide whether an element is required or optional?
Why do some elements get maxOccurs="unbounded"?
Does it detect data types like numbers, booleans and dates automatically?
What happens to XML namespaces and prefixes?
Can it handle deeply nested or self-referencing XML, like a folder tree?
Will the schema this tool generates validate my original XML file?
What if my XML mixes text and child elements in the same tag?
Is my XML uploaded to a server?
Can I set a target namespace for the generated schema?
Related Tools
XML Formatter
Format and beautify XML code.
XML to JSON Converter
Convert XML data to JSON format instantly. Simple, fast, and free online converter.
XML Validator
Validate your XML syntax and structure against standard rules.
XML to CSV Converter
Convert XML data to CSV format instantly. Extract structured data from XML.
JSON to XML Converter
Transform JSON data into XML format.
XPath Test Tool
Test and validate XPath expressions against XML or HTML documents. Debug queries instantly.
The XML to XSD Converter is maintained by CodeItBro. We aim to provide the best free developer tools on the web. If you have feedback or suggestions, please visit our contact page.

