Home › Developer Tools › XML to XSD Generator

XML to XSD Generator

Paste one or more sample XML documents and get an XML Schema (XSD 1.0) that describes them: element structure, data types such as xs:int, xs:decimal and xs:date, which elements are optional or repeated, attributes and their required status, and the target namespace. Choose Russian doll, Salami slice or Venetian blind layout.

Last updated:

Several samples of the same format give a better schema: elements missing from some samples become optional and repeated ones get maxOccurs="unbounded".

Inferred structure
ElementType / contentOccursAttributes

Everything is generated in your browser; your XML is never uploaded. Review the result: a schema inferred from samples only knows the values it has seen.

Advertisement
Advertisement

How to use the XML to XSD Generator

  1. Paste a sample XML into the left box, open one or more .xml files, or load the two book catalog samples.
  2. Add more samples with + Add sample: the more real documents you give, the more accurate the optional and repeated elements are.
  3. Pick a schema design and options such as type detection, enumerations and annotations.
  4. Review the XSD and the Inferred structure table; adjust types or occurrences that your samples could not reveal.
  5. Copy or download the schema as an .xsd file.

How sample values map to XSD built-in types

Values seenInferred typeNotes
true, falsexs:booleanXSD also allows 1 and 0, but those are typed as numbers to avoid false matches.
42, -7xs:intWithin ±2,147,483,647; larger values become xs:long, then xs:integer.
44.95, .5xs:decimalExact decimal, ideal for prices and quantities.
1.5E3, INFxs:doubleUsed when values contain an exponent or special values.
2024-05-01xs:dateISO 8601 date, optional time zone.
2024-05-01T09:30:00Zxs:dateTimeDate and time with optional fraction and time zone.
14:30:00xs:timeSeconds are required by the XSD lexical form.
P3DT4Hxs:durationISO 8601 durations.
https://…, mailto:…xs:anyURIOnly when every value starts with a URI scheme.
00123, mixed or empty valuesxs:stringLeading zeros and empty instances keep the type permissive.

Using the generated XSD

  • Reference it from XML: declare the xmlns:xsi prefix for the XML Schema instance namespace (http://www.w3.org/2001/XMLSchema-instance) on the root element, then point to the file with the xsi:noNamespaceSchemaLocation attribute (value: catalog.xsd) when there is no namespace, or with xsi:schemaLocation (value: the namespace, a space, then catalog.xsd) when there is one.
  • Tighten it: add maxLength, pattern or minInclusive facets, and turn small fixed value sets into enumerations (the Detect enumerations option suggests them).
  • Generate code: the Venetian blind layout produces named types that map cleanly to classes in JAXB (xjc), .NET (xsd.exe) and similar tools.
  • Validate documents against the schema with xmllint (xmllint --noout --schema catalog.xsd file.xml) or your IDE; tidy the sample files first with the XML Formatter.

Working with JSON instead? The JSON Schema Generator does the same job for JSON documents.

Frequently asked questions

How does the generator decide the data type of a value?

It looks at every value an element or attribute has across all samples. If all are true/false it uses xs:boolean; if all are whole numbers, xs:int (or xs:long/xs:integer for large values); decimals become xs:decimal; ISO 8601 values become xs:date, xs:dateTime or xs:time; URLs become xs:anyURI. Anything else, or a mix, is xs:string.

Why is a number like 00123 typed as a string?

Leading zeros usually mean an identifier (ZIP code, account or product number) rather than a quantity. Typing it as an integer would make a validator accept 123 and lose the zeros in many tools, so such values stay xs:string.

How are minOccurs and maxOccurs calculated?

For each parent element, the tool counts how often each child appears in every instance. A child missing from at least one instance gets minOccurs="0"; a child that appears more than once in any instance gets maxOccurs="unbounded". Defaults (1) are not written out.

What is the difference between Russian doll, Salami slice and Venetian blind?

Russian doll nests every declaration inside its parent, giving one compact global element. Salami slice declares every element globally and links them with ref, which makes elements reusable. Venetian blind declares named complex types (bookType, catalogType) and uses local elements, which suits code generators like JAXB and xsd.exe.

Can I trust the generated schema as-is?

Treat it as a strong first draft. It only knows what the samples contain: an element that is optional but present in all your samples will be marked required, and a field that happened to contain only numbers will be typed as a number. Review the types and occurrences before using the schema for validation.

Does it support namespaces?

Yes. The root element's namespace becomes the targetNamespace with elementFormDefault="qualified". Elements from other namespaces are allowed through xs:any, and xml:lang style attributes are referenced from the standard XML namespace schema.

Is my XML uploaded?

No. The XML is parsed with your browser's built-in DOMParser and the schema is generated locally. Your files never leave your device.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

XML FormatterBeautify, validate and minify XML with a collapsible tree view.XML to JSONConvert XML to JSON with validation.JSON Schema GeneratorTurn sample JSON into a draft 2020-12 JSON Schema with types, required fields and formats.XML MinifierMinify and validate XML: strip whitespace and comments, keep CDATA, see the size savings.XML ViewerBrowse XML as a collapsible tree with search, XPath of any node, attributes and big-file support.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.CSV Column ExtractorPick, reorder and rename CSV columns, filter rows by value, and export a new CSV or JSON.CSV Diff CheckerCompare two CSV files by key column and see added, removed and changed rows cell by cell.CSV Duplicate Row RemoverRemove duplicate rows from a CSV by all or selected columns and download the cleaned file.CSV to HTML TableTurn CSV into clean HTML table code with a live preview, styling options and one-click copy.CSV to Markdown TableConvert CSV to a neatly aligned GitHub Markdown table with column alignment and live preview.CSV TransposeSwap rows and columns of CSV, TSV or pasted spreadsheet data, with delimiter auto-detect.Date Format ConverterConvert any date to ISO 8601, RFC 2822, Unix time and custom strftime, moment or Java patterns.ENV to JSON ConverterConvert .env files to JSON or YAML and JSON back to .env, with quotes and multiline values.File to Base64Convert any file to a Base64 string or data URI with MIME detection, line wrap and download.HTML Table to CSVExtract any table from HTML or page source to CSV, TSV or JSON, with colspan and rowspan handled.IEEE 754 Floating Point ConverterConvert decimals to 32/64-bit IEEE 754 floats: toggle bits, see hex, exact value and rounding error.INI to JSON ConverterConvert INI and CFG files to JSON and JSON back to INI, with sections, arrays and types.IP Address ConverterConvert IPv4 to decimal, hex, binary, octal and back, with class and private/public check.ISBN Converter & ValidatorConvert ISBN-10 to ISBN-13 and back, validate check digits and hyphenate, one or in bulk.JSON Flatten / UnflattenFlatten nested JSON to dot or bracket path keys, or unflatten flat keys back to nested JSON.JSON to Dart ClassTurn JSON into Dart model classes with fromJson, toJson, null safety and nested classes.JSON to Java ClassTurn JSON into Java POJOs or records with Lombok, getters/setters and Jackson or Gson annotations.JSON to Kotlin Data ClassTurn JSON into Kotlin data classes for kotlinx.serialization, Gson, Moshi or Jackson.JSON to Markdown TableTurn a JSON array of objects into a GitHub Markdown table with column picker and alignment.JSON to PHP ArrayConvert JSON to PHP array code (short [] or array()) and PHP arrays back to JSON.JSON to Rust StructTurn JSON into Rust structs with serde derives, rename attributes, Option and Vec types.JSON to SQL ConverterConvert a JSON array of objects to CREATE TABLE and INSERT statements for MySQL, Postgres, SQLite.JSON to Swift StructTurn JSON into Swift Codable structs with CodingKeys, optionals and nested types.JSON to TOML ConverterConvert JSON to clean TOML with tables, arrays of tables, inline tables and dates.JSONL to JSON ConverterConvert JSON Lines / NDJSON to a JSON array and back, with line-level error reports.Properties to YAML ConverterConvert Java .properties to nested YAML (application.yml) and YAML back to properties.PX to EM ConverterConvert pixels to em using the parent font size, and em back to px, with conversion tables.Query String to JSONConvert URL query strings to JSON with nested brackets and arrays, and JSON back to a query string.REM to PX ConverterConvert CSS rem values to pixels for any root font size, with a quick 0.25–6rem table.SQL to JSON ConverterConvert SQL INSERT statements and dumps into a JSON array of row objects, with CSV export.
See all 129 Data & File Format Converters →