XML to XSD Schema Generator
Infer W3C XML Schema (.xsd) definitions from XML instances with automatic data type detection and unbounded cardinality.
Client-Side Execution & Privacy Guarantee
This utility executes 100% locally in your web browser. Your inputs, tokens, queries, and data payloads are never transmitted to any external server or backend.
When you have sample XML but no formal schema, inferring an XSD gives you a starting contract for validation, code generation, and documentation. The generator examines element and attribute names, text content patterns, and occurrence counts to produce a reasonable W3C XML Schema.
Because inference works only from the examples you supply, the resulting schema is a lower bound on what the real documents may contain. Feed multiple representative instances when possible so optional elements and alternative content models are captured instead of being locked to a single document shape.
Type detection and cardinality
Numeric text is mapped to the narrowest suitable built-in type (integer, decimal, or double) when every observed value matches; otherwise the type falls back to string. Dates and times are recognized only when they match common lexical forms. Attributes receive use="required" or use="optional" according to whether they appear in every instance of their parent.
Repeated sibling elements of the same name become maxOccurs="unbounded". Elements that appear in some documents but not others receive minOccurs="0". Mixed content and text-only elements are distinguished by the presence or absence of child elements.
Namespaces and form defaults
A targetNamespace is emitted when the input documents declare a default or prefixed namespace on the root. elementFormDefault and attributeFormDefault are set to qualified or unqualified to match the majority of the observed markup. Imported schemas are not generated; only the structures visible in the supplied instances appear.
Local element declarations are preferred for nested structures so that the same element name can have different types in different contexts. Global elements are created only for roots and for elements that appear in multiple distinct parent contexts.
Limits of pure inference
Identity constraints (key, keyref, unique), enumeration facets, and pattern facets cannot be reliably derived from positive examples alone. The generated schema therefore uses the most permissive simple type that fits the observed values. Complex type derivation and substitution groups are likewise omitted.
If your documents contain choice constructs or ordered sequences that vary, the inference engine produces a sequence of optional elements rather than an xs:choice. Review the result and tighten it manually before treating the schema as authoritative.
When to use this tool
- You received XML samples from a partner and need a schema to start validating future messages.
- You want a quick XSD to drive code generation or documentation from existing instance documents.
- You are exploring an unfamiliar XML dialect and need a readable structural overview.
- You need a baseline schema that you will later refine with explicit facets and constraints.
- Multiple sample files exist and you want a single schema that covers their union.
How to use the XML to XSD Schema Generator
- Paste one or more well-formed XML documents into the input area, separating multiple documents with a blank line or using the multi-file controls.
- Confirm that each document is well-formed; the generator rejects malformed input.
- Click Generate Schema. The tool scans every element and attribute and emits a complete xs:schema.
- Inspect the generated XSD for type choices and cardinality that match your expectations.
- Copy or download the schema. Optionally feed it into the XSD validator with additional instances to test coverage.
- If the schema is too loose, add more diverse sample documents and regenerate.
- Manually edit the XSD to add enumerations, patterns, or identity constraints that inference cannot discover.
Worked examples
Simple product list
<products>
<product id="A1">
<name>Widget</name>
<price>9.99</price>
</product>
<product id="B2">
<name>Gadget</name>
<price>14.50</price>
</product>
</products>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="products">
<xs:complexType>
<xs:sequence>
<xs:element name="product" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Repeated product elements become unbounded; price values are recognized as decimal.
Optional supplier field
<item sku="X9"> <title>Cable</title> </item> <item sku="Y8"> <title>Adapter</title> <supplier>Acme</supplier> </item>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="item">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="supplier" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="sku" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
Supplier appears in only one document, so minOccurs is set to 0.
Common mistakes and tips
- Always supply at least two structurally different documents when optional elements exist; a single document produces a schema that treats every observed element as required.
- Numeric-looking identifiers such as product codes are frequently inferred as integers; if leading zeros matter, force the type to string after generation.
- Namespaces must be consistent across the supplied documents or the generator will produce a schema without a targetNamespace.
- The tool does not invent choice particles; if your real schema uses xs:choice, expect a sequence of optionals that you will need to rewrite.
- Validate the generated schema against the original samples immediately; any mismatch indicates that the inference missed a variation present in the input.
Frequently asked questions
Why did an element become optional when it always appears in my samples?
If any of the supplied documents omits the element, the generator sets minOccurs="0". Check that every sample truly contains the element.
Can the tool infer enumerations from repeated values?
No. Inference never emits enumeration facets. You must add them manually after reviewing the distinct values that appeared.
What happens with mixed content?
Elements that contain both text and child elements are modeled as complex types with mixed="true". Pure text elements remain simple types.
Does the generator support XML Schema 1.1 constructs?
No. Only XSD 1.0 structures (element, complexType, simpleType, attribute) are produced. Assertions and other 1.1 features are outside the scope of inference.
How are attributes without values treated?
Empty attributes are still recorded. Their type defaults to string and their use is determined solely by presence across instances.