XML to Code Generator
Paste an XML document and pick a target language — TypeScript, JavaScript, Python, Go, Java, C#, Kotlin, Rust, Dart, Objective-C or JSON Schema. The document is parsed to the same shape a JSON payload would produce and the same inference runs over it, so nested elements become nested types and repeated elements become arrays. XML carries no type information, so values that look like numbers or booleans are read as such and anything ambiguous stays a string.
How it works
Paste a representative XML sample and the chosen language’s declarations appear on the right. The types are inferred from what is actually in the sample, so the more complete your example, the better the result — one array element with an extra field is enough to have that field marked optional rather than missed.
XML has no types: every element and attribute is text as far as the document is concerned. Values that look like numbers or booleans are read as such, but anything ambiguous comes through as a string — so check the generated types against what the producer actually sends. Attributes appear as fields prefixed with @_ , which is how they are kept apart from child elements of the same name.
Every object in the sample becomes an exported interface, named after the key that held it. Arrays become typed arrays, and an array of objects contributes one interface for its items rather than one per element.
A field missing from some records in an array is marked optional with a question mark, and a field that was null somewhere is unioned with null — so the types describe what the data can actually be, not just what the first record happened to contain.
Generation runs entirely in your browser — nothing you paste is uploaded.
Frequently asked questions
Why do some XML values come out as strings when they look like numbers?
XML has no type system — as far as the document is concerned every element and attribute is text. Values that unambiguously parse as a number or boolean are read as such, but anything else stays a string, so it is worth checking the generated types against what the producer actually sends.
How are XML attributes represented?
Attributes appear as fields prefixed with @_ , which keeps them distinct from a child element that happens to have the same name. Rename them in the generated declarations if your parser maps them differently.
Does a repeated element become an array?
Yes — repeated sibling elements are unified into one array type, and their shapes are merged, so a field present in only some of them comes out marked optional rather than being missed.
Is malformed XML detected?
The document is checked for well-formedness before anything is inferred. A missing or mismatched closing tag is reported with its position rather than being parsed leniently into declarations that would look confident but be wrong.
Should I use an XSD instead if I have one?
If you have an XSD it is a better source than a sample, because it states the types and cardinalities rather than leaving them to be guessed. This tool is for the common case where all you have is an example document.
Related tools
YAML to Code Generator
Turn a YAML sample — a config file, a manifest — into typed declarations in any of eleven languages.
XML to JSON Converter
This XML to JSON converter parses XML into JSON online, preserving attributes and repeated tags as arrays.
JSON to TypeScript Converter
This JSON to TypeScript converter turns a sample payload into exported interfaces.