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.

XML input

Leave empty for a schema with no namespace.

Element form default
Indent size

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.

Runs entirely in your browser

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.

How the type inference works
XML patternWhat the tool checksXSD result
Same tag appears twice under one parentCounts the highest number of siblings seen anywheremaxOccurs="unbounded"
A child tag is missing from one recordChecks if the tag appears under every parent instanceminOccurs="0"
Text is always whole numbersTests every sampled value against an integer patternxs:integer
Text mixes whole numbers and decimalsEvery integer is also a valid decimalxs:decimal
Text mixes numbers and wordsNo single pattern matches every sampled valuexs:string (safe fallback)
An element contains other elementsBuilds a named, reusable complex typexs:complexType with xs:sequence
An element has a namespace prefixPrefix is stripped before analysisLocal 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

1

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.

2

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.

3

Generate the schema

The tool walks the whole document, merges repeated tags, and infers minOccurs, maxOccurs and data types for every element and attribute.

4

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:

Input
A two-book <catalog> with a currency attribute and one optional field
Output
<xs:element name="catalog" type="CatalogType"/> <xs:complexType name="BookType"> <xs:sequence> <xs:element name="title" type="xs:string" minOccurs="1"/> <xs:element name="price" type="xs:decimal" minOccurs="1"/> <xs:element name="inStock" type="xs:boolean" minOccurs="0"/> </xs:sequence> <xs:attribute name="id" type="xs:string" use="required"/> </xs:complexType>

Frequently Asked Questions

What is an XSD schema, and why would I generate one from an XML file?
An XSD (XML Schema Definition) describes the shape a family of XML documents must follow: which elements and attributes are allowed, in what order, how many times they can repeat, and what data type each value should be. Writing one by hand is slow, so this tool reads a real XML document and builds a schema that matches it.
How does the tool decide whether an element is required or optional?
It looks at every place a tag appears under the same parent tag across your document. If it shows up under every single instance of that parent, the schema sets minOccurs="1". If even one instance of the parent is missing it, minOccurs drops to "0" so the schema still accepts documents where that field is left out.
Why do some elements get maxOccurs="unbounded"?
That happens whenever the tool finds more than one sibling with the same name under any instance of the parent element, such as multiple <book> tags inside <catalog>. A tag that only ever appears once keeps maxOccurs="1", which is the XSD default and is left out of the output to keep the schema readable.
Does it detect data types like numbers, booleans and dates automatically?
Yes. The tool samples the text or attribute values it finds for each element and checks them against patterns for whole numbers, decimals, true/false booleans, dates and date-times. If every sample fits one pattern, that becomes the XSD type, for example xs:integer or xs:date. Whole numbers mixed with decimals become xs:decimal, since every integer is a valid decimal. If the values otherwise disagree, it falls back to xs:string so nothing gets rejected.
What happens to XML namespaces and prefixes?
Namespace prefixes are stripped before the schema is built, and the generated schema describes local element names only. Reliably inferring a namespace-aware structure from a single sample document is not something a generic tool can get right every time, so this is a known limit rather than a silent guess.
Can it handle deeply nested or self-referencing XML, like a folder tree?
Yes. Each distinct tag name gets one shared complex type, so a recursive structure, such as a <node> that contains more <node> elements, reuses the same type definition instead of unrolling forever. The schema stays finite no matter how deep your sample document goes.
Will the schema this tool generates validate my original XML file?
It is built specifically to match the document you gave it, so validating that same file against the output should pass. A schema inferred from one example is a good starting point for documents shaped the same way, but it can be stricter or looser than you want for edge cases the sample never showed, so review it before using it in production.
What if my XML mixes text and child elements in the same tag?
That is called mixed content, for example <p>Hello <b>world</b></p>. The tool detects it and adds mixed="true" to that element's complex type so the schema stays valid, though it does not try to pin down exactly where the loose text falls between the child elements.
Is my XML uploaded to a server?
No. Parsing and schema generation both run in your browser using JavaScript. Nothing you paste or upload ever leaves your device.
Can I set a target namespace for the generated schema?
Yes. Enter a namespace URI in the schema options and the tool adds targetNamespace and xmlns to the generated <xs:schema> element, and applies the elementFormDefault you choose. Leave the field empty for a schema with no namespace, which is the more common case for internal or config-style XML.

Related Tools

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.

As featured on

CodeItBro - Free dev tools + practical guides to help you ship faster | Product HuntCodeItBro - Free Online Developer Tools badgeCodeItBro badge