XML to TypeScript screenshot

XML to TypeScript

Turn an XML sample into typescript interfaces: one type per element, attributes as fields, repeated child elements as lists.

Privacy First
0 Runs
Updated 2026-11-17
Runs in your browser
No sign-up, no upload

What the XML to TypeScript does

An element with children is an object; an element with only text is a string. A name that appears more than once among the children is a list of that element's shape, which is how XML says "repeated" without a schema.

Attributes are attributes and child elements are both properties, because they are part of the element rather than a child of it.

Text content is not modelled: an element with children contributes its children, not its mixed text. Namespaces are kept as they appear in the tag name, so a prefixed element produces a prefixed field name that may need rewriting.

How to use it

Paste the XML into the XML sample box, or press Run with the example already there.

Read the typescript interfaces below: the root element is the last type, and each child element type appears before it.

Check a repeated element in the TypeScript interfaces — it is a list because the same name appears more than once among the siblings.

Worked example

Input:

<user id="7"><name>Ada</name><address><city>London</city></address><tag>a</tag><tag>b</tag></user>

Output:

export interface Address {
  city: string;
}

export interface User {
  id: string;
  name: string;
  address: Address;
  tag: string[];
}

Why it runs in your browser

The result is produced on this page with JavaScript, so it works offline after the page loads and nothing you enter is sent anywhere.

A shape read from the element tree: the root element names the first type, its attributes become fields, and a child that repeats becomes a list.

The page parses the document before it emits anything, so a tag closed in the wrong place is refused with its line number instead of producing a type tree that silently disagrees with the file.

What it does, and what it does not

An element with children is an object; an element with only text is a string. A name that appears more than once among the children is a list of that element's shape, which is how XML says "repeated" without a schema.

Attributes are attributes and child elements are both properties, because they are part of the element rather than a child of it.

Text content is not modelled: an element with children contributes its children, not its mixed text. Namespaces are kept as they appear in the tag name, so a prefixed element produces a prefixed field name that may need rewriting.

How to use XML to TypeScript

Paste the XML into the XML sample box, or press Run with the example already there.

Read the typescript interfaces below: the root element is the last type, and each child element type appears before it.

Check a repeated element in the TypeScript interfaces — it is a list because the same name appears more than once among the siblings.

What to Expect

Best for

  • Starting TypeScript types from a real response body
  • Seeing how attributes map into TypeScript

Not ideal for

  • Mixed content, where text and elements interleave
  • A schema-driven mapping, which needs an XSD

What this tool keeps

  • One type per element, named from the tag
  • A repeated child as a list

What may need cleanup

  • A namespace prefix stays in the field name
  • Mixed text is dropped, so a prose element needs hand work

Common errors

  • The page refuses it: </user> closes <name>

Example use cases

  • Typing a SOAP or REST response in TypeScript
  • Checking an element shape before writing the structs

Sample input

XML sample: <user id="7"><name>Ada</name><address><city>London</city></address><tag>a</tag><tag>b</tag></user>

Sample output

TypeScript interfaces: export interface Address { …

Who this is for

  • TypeScript developers consuming an XML API
  • Anyone porting an XML document into typed code

Frequently asked questions

Why is a repeated element a list?

More than one child with the same name is how XML expresses repetition without a schema. One occurrence is a single value; two or more become a list of that element's shape.

What happens to text inside an element that also has children?

It is dropped. A mixed-content element has no single shape, and inventing one would misrepresent the document; the page models elements and attributes only.

Are namespaces resolved?

No. The prefix stays in the tag name and therefore in the type name, so soap:Body becomes a field named after the prefixed tag. Rename it where your code needs it.

Developer program

Build custom tools for your store

Join the SDK program to create useful ecommerce utilities for your store.