Skip to content
{}

XML to XSD Converter

Generate a well-formed XSD 1.0 XML Schema from sample XML with inferred types, optionality, attributes, and repeating sequences.

0 chars | 1 lines
0 chars | 0 lines

Conversion payloads stay in this browser tab and are never placed in page URLs - see how local processing works. Privacy-safe analytics record only the tool, outcome, and a coarse input-size bucket.

How to Generate an XSD from XML

Paste or upload a representative XML document and the converter produces a well-formed W3C XML Schema 1.0 (http://www.w3.org/2001/XMLSchema) document instantly. Download it as a .xsd file or copy it directly into your project. For best results, include two or more repeated records in your sample so optional elements and attributes are inferred automatically.

Type & Structure Inference Rules

Every leaf value and attribute is inspected across all merged samples before assigning an XSD type.

InputOutputNote
<pages>420</pages>type="xs:integer"Arbitrary-size integers kept exact
<zip>02134</zip>type="xs:string"Leading zeros preserved as text
<price currency="USD">44.95</price>xs:simpleContent extensionText + attributes
<published>2025-06-15</published>type="xs:date"Validated calendar date
<p>Hello <b>world</b></p><xs:complexType mixed="true">Mixed content detected

Validating XML Against Your XSD

Once you refine and save the generated schema as schema.xsd, validate XML documents locally or in CI:

xmllint (CLI)

xmllint --noout --schema schema.xsd document.xml

Python (xmlschema)

import xmlschema
schema = xmlschema.XMLSchema("schema.xsd")
schema.validate("document.xml")

Frequently Asked Questions

How does the generator infer minOccurs, maxOccurs, and required attributes?

All repeated instances of a sibling element are merged before emitting its schema definition. A child element that appears more than once inside any parent receives maxOccurs="unbounded", and a child omitted from any parent instance receives minOccurs="0". Attributes present on every instance become use="required"; attributes missing from at least one instance become use="optional".

Which XSD built-in data types are inferred?

The generator distinguishes xs:boolean, xs:integer, xs:decimal, xs:date, xs:dateTime, xs:time, xs:anyURI, and xs:string. Mixing integers and decimals across samples widens cleanly to xs:decimal; mixing incompatible types falls back to xs:string. Multi-digit leading-zero values such as ZIP codes (02134) stay xs:string so leading zeros are never stripped.

How are elements with both text and attributes handled?

An element like <price currency="USD">44.95</price> cannot be declared with a bare type attribute in XSD. It is emitted as a complexType with <xs:simpleContent><xs:extension base="xs:decimal"> and its <xs:attribute> declarations inside the extension, which is valid W3C XSD 1.0.

What does it do with xmlns declarations and mixed content?

Namespace declarations (xmlns and xmlns:*) are never emitted as ordinary attributes. A default xmlns on the root element is promoted to targetNamespace on <xs:schema>, and elements that contain both text and child elements are marked mixed="true" with a conversion note.

Can an inferred XSD replace a hand-reviewed contract?

Treat it as an accurate starting draft. Sample-based inference can only see fields, types, and enumerations present in your example XML—give it several representative records covering optional fields, then tighten facets (length, patterns, enums) by hand.

Does my XML stay private?

Yes. Schema inference runs 100% client-side in your browser tab with zero server uploads, and nested DOCTYPE entities are refused before parsing.

APIs & data workflow

Continue with the data, not the directory

Prepare CSV, XML, tables, SQL, and DynamoDB payloads for the next system in the workflow.

Browse apis & data handoff