XML to TypeScript Interface Generator
Interfaces typed from your XML sample
XML Input
TypeScript Output
Paste your XML on the left and the TypeScript code shows up here.
Or drop a file on this box, , or .
What the generator writes
Paste an XML sample and you get an exported TypeScript interface (or type) per element name. Keys keep the exact XML names, quoted when they are not valid identifiers, so item-list stays 'item-list' and still matches the parsed object.
Values are typed from what you paste: whole numbers and decimals become number, true/false becomes boolean, and numbers with a leading zero stay string. Integers bigger than Number.MAX_SAFE_INTEGER are typed string with a comment, because a JS number would round them. Repeated elements become arrays, and fields missing from some records can be optional.
Attributes use an @_ prefix and text next to attributes uses #text, the same keys fast-xml-parser produces with ignoreAttributes: false. Other parsers name things differently, so adjust the keys if yours does. The XML is parsed in your browser with DOMParser and not uploaded.
How to use it
Paste, pick a style, copy.
Paste a sample
Drop XML into XML Input or open a file with Upload. Only an element seen more than once inside the same parent turns into an array, so the first sample article carries two <tag> children to make tag: string[]. Sample loads an article feed:
<feed updated="2026-03-02T08:00:00Z">
<article id="A-1001"><title>Shipping Flutter builds faster</title><readMinutes>6</readMinutes></article>
<article id="A-1002" featured="true"><title>Offline sync</title><readMinutes>9</readMinutes></article>
</feed> If the markup is broken you get the parser message in place of interfaces. Paste the same text into the XML Validator to find the line it chokes on.
Choose interface or type
Root type names the outer type; blank turns <feed> into Feed. interface (not type) chooses between export interface Feed { ... } and export type Feed = { ... };. Optional for missing fields adds the ? you see on '@_featured'?, since only one article carries that attribute.
Copy or download
Download saves a .ts file; Copy puts it on the clipboard. The output passes tsc --strict.
Where it helps
Typing a parsed XML response
Cast the result of your XML parser to the generated root type and get autocomplete for every field.
RSS and sitemap tooling
Scripts that read feeds or sitemaps get types for items, links and dates in one paste.
Migrating an XML API to JSON
Types generated from the old XML payload document what the new JSON contract has to cover.
Code review
A short types file is easier for reviewers to check than a long sample document.
Common questions
Which parser do the keys match?
The defaults of fast-xml-parser with ignoreAttributes: false: @_ before attribute names and #text for text next to attributes. Elements without attributes are plain values.
Will my parser return numbers or strings?
That depends on its settings. The interfaces assume numeric text is parsed into numbers. Some parsers turn 02134 into 2134 unless you change their number options, so check that if you rely on leading zeros.
Why is a long ID typed as string?
It is larger than 2^53 − 1, so a JavaScript number cannot hold it exactly. Keep it as a string, or a BigInt if you need arithmetic.
What about elements that appear only once in my sample?
They are typed as a single value. Most parsers only return an array when an element repeats, so if a list can have one entry, configure your parser to always return arrays for it and change the type to T[].
Can I get type instead of interface?
Yes, untick interface (not type). The shapes are identical; the choice is just style.
Is the XML uploaded?
No. DOMParser runs in this tab and the TypeScript is written there as well, so nothing is posted anywhere. Anything bigger than 256 KB is refused; a feed with a couple of entries is all the type inference needs.
Related tools
Other converters you might reach for next: