XSD to XML Sample Generator
Synthesize conforming, realistic XML sample documents from W3C XSD schemas with sample data.
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.
A schema defines the legal shape of XML but does not supply concrete documents. The sample generator walks the XSD, respects minOccurs and maxOccurs, and emits well-formed instance documents populated with plausible values for each simple type.
Generated samples are useful for unit tests, documentation, and exploratory validation. They are not a substitute for production data; identity constraints, pattern facets, and abstract types may produce documents that still require manual adjustment before they fully satisfy every rule.
Cardinality and choice handling
For each element the generator emits the minimum number of occurrences required by minOccurs (at least one when the attribute is absent). When maxOccurs is unbounded it produces a small fixed number of siblings so the document remains readable. Optional elements (minOccurs="0") are included by default so that the sample illustrates the full content model.
xs:choice particles are resolved by selecting the first alternative. xs:sequence is followed in order. Substitution groups and abstract elements are skipped or replaced by the first concrete substitute that can be resolved from the same schema document.
Sample value generation
Built-in types receive canonical lexical values: integers become small positive numbers, decimals become values with two fractional digits, dates become a fixed recent date, and strings become short alphanumeric tokens. Enumeration facets are honored by picking the first listed value. Pattern facets are not guaranteed to be satisfied; the generator prefers readability over exhaustive facet compliance.
Attributes marked use="required" always appear. Fixed and default values from the schema are copied verbatim. Namespace prefixes are declared on the root element so that the generated document is self-contained.
Practical limitations
Key, keyref, and unique constraints are ignored during generation because satisfying them requires global analysis that is expensive in the browser. Documents that rely on these constraints will validate only after you edit the sample. Recursive content models are expanded to a depth of three to avoid infinite documents.
External schema documents referenced by xs:import or xs:include are not fetched. Only types and elements defined in the schema text you paste are available. If a type is missing the generator inserts a placeholder element and continues.
When to use this tool
- You need a quick conforming XML document to test a parser or validator.
- You are writing documentation and want a realistic example that matches the published schema.
- You are building a test suite and need baseline instances that exercise required structure.
- You want to see how optional elements and attributes look when populated.
- You received an XSD from a partner and need a concrete starting point for implementation.
How to use the XSD to XML Sample Generator
- Paste a complete, well-formed XSD into the schema input area.
- Select the root element if the schema defines more than one global element.
- Optionally adjust the number of repeating elements or toggle inclusion of optional content.
- Click Generate Sample. The tool produces one XML document in the output pane.
- Copy the result and, if desired, paste it into the XSD validator together with the original schema to confirm validity.
- Edit any values that must satisfy patterns or identity constraints the generator could not honor.
- Regenerate after schema changes to keep samples synchronized with the contract.
Worked examples
Person record schema
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="age" type="xs:positiveInteger"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <person id="ID1"> <name>SampleName</name> <age>42</age> </person>
Required attribute and both elements are present with type-appropriate values.
Order with optional notes
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="order">
<xs:complexType>
<xs:sequence>
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="sku" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="notes" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="UTF-8"?> <order> <item sku="SKU001"/> <item sku="SKU002"/> <notes>Sample notes text</notes> </order>
Unbounded item appears twice; the optional notes element is included.
Common mistakes and tips
- Always validate the generated sample against the original schema; generators cannot guarantee satisfaction of every facet or identity constraint.
- If the schema uses a targetNamespace, confirm that the generated document declares the matching xmlns and, if needed, an xsi:schemaLocation.
- Large recursive schemas can produce deeply nested documents; limit depth or simplify the schema before generating production-scale tests.
- Enumeration and fixed values are respected; pattern facets and regular expressions are not, so review those fields by hand.
- For multi-file schemas, concatenate the relevant schema documents or use a single self-contained XSD before pasting.
Frequently asked questions
Why does the sample sometimes fail validation?
Identity constraints, complex pattern facets, and certain 1.1 assertions are not fully enforced during generation. Manual correction of the sample is required in those cases.
Can I control how many repeating elements appear?
The generator uses a small fixed count for unbounded particles. You can edit the output or regenerate after adjusting schema maxOccurs for temporary control.
Are namespaces preserved?
Yes. The root element receives the targetNamespace as its default xmlns when one is declared in the schema.
What happens with abstract elements?
Abstract elements are replaced by the first concrete element in a substitution group that the schema defines; if none exists the element is omitted.
Does generation work with XSD 1.1?
Only constructs that are valid in XSD 1.0 are processed. Assertions and other 1.1-only features are ignored.