XML to TypeScript Interface Generator
Interfaces typed from your XML sample
XML Input
TypeScript Output
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
Paste XML into XML Input or Upload a file. Repeated elements must appear twice to become arrays. 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>Parse errors appear in the output panel. The XML Validator shows where.
Choose interface or type
Root type renames the top-level type (empty uses the root element name). interface (not type) switches between export interface and export type. Optional for missing fields adds ? to fields that are absent in some records.
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. It is parsed in your browser. Inputs over 256 KB are rejected.
Related tools
Other converters you might reach for next: