XML to TypeScript Converter Online — Generate Interfaces

Paste any XML and generate typed TypeScript interfaces shaped for fast-xml-parser. XML attributes become "@_name" string-literal keys, child elements become bare keys, and nested structures get their own interfaces — all in your browser.

What is an XML to TypeScript converter?

An XML to TypeScript converter takes a real XML document and emits exported interface definitions shaped for the JavaScript object that fast-xml-parser produces when it parses that XML. The OpenFormatter generator inspects every element and attribute, infers TypeScript types, and produces a complete interface hierarchy with "@_name" keys for attributes and "#text" for inner text — saving the tedious step of writing the types by hand for SOAP, RSS, or config XML in a Node or browser app.

XML differs from JSON in two ways your TypeScript interface has to honour. First, XML has attributes on elements (<book id="bk101">) — these surface as "@_id" string-literal keys (the fast-xml-parser default). Because @ is not a valid bare identifier, the key is quoted, which also visually separates attributes from element children. Second, XML has namespaces; the basic generator strips them, but you can preserve the prefix as part of the key string. Both aspects are handled by the sample below.

Sample XML and the TypeScript interface it generates

Input XML

<book id="bk101" lang="en">
  <title>Programming TypeScript</title>
  <year>2019</year>
  <price currency="USD">39.99</price>
</book>

Generated TypeScript

export interface Book {
  "@_id": string;        // XML attribute
  "@_lang": string;      // XML attribute
  title: string;
  year: number;
  price: Price;
}

export interface Price {
  "@_currency": string;
  "#text": number;
}

Notice "@_id" and "@_lang" are quoted because the leading @ is not a valid identifier — TypeScript permits string-literal keys for exactly this case. The nested <price currency="USD">39.99</price> generates a Price interface with one attribute key and one "#text" key for the text body — exactly what fast-xml-parser produces.

How to convert XML to TypeScript — 4 steps

  1. Paste your XML. A SOAP envelope body, an RSS feed entry, an OPML outline — anything well-formed.
  2. Click Convert. The browser parses the XML and generates exported TypeScript interfaces for the full element tree.
  3. Review attribute keys. Confirm "@_name" appears for every XML attribute and "#text" for any mixed content.
  4. Cast and type your parser output. Copy the interfaces and use parser.parse(xml) as Root with fast-xml-parser to get full type safety on the parsed result.

fast-xml-parser Shaped

Interfaces match the default fast-xml-parser output shape: attributes prefixed with @_, text content under #text, repeated elements as arrays. Cast and type the parser output with no glue code.

Attribute vs Element

XML attributes get @_-prefixed string-literal keys, child elements get bare keys. The distinction is preserved exactly so type errors surface when you confuse the two in code.

Client-Side Only

Your XML — including SOAP responses with credentials — is parsed in JavaScript on your machine. Verify in DevTools: zero network requests on Convert.

Common use cases

  • check_circleType a fast-xml-parser parse result for a SOAP response in Node
  • check_circleGenerate TS interfaces for an RSS or Atom feed reader
  • check_circleType Axios XML responses parsed with fast-xml-parser
  • check_circleAdd type safety to OPML, sitemaps.xml, or robots.xml processing
  • check_circleGenerate TypeScript types from an XSD-described XML payload
  • check_circleType SAML or WS-Security XML envelopes in a TypeScript service
  • check_circleBuild typed parsers for AWS XML responses (S3, SQS, SNS) in TS
  • check_circleType Apple plist XML when working with cross-platform tooling

Why client-side conversion matters

SOAP responses and enterprise XML often contain customer PII, API tokens, internal endpoint names, and database identifiers. Pasting them into a server-hosted converter is a compliance violation in most regulated industries. OpenFormatter parses the XML and generates TypeScript code entirely in JavaScript on your device — no upload, no logs, no cookies. Open DevTools → Network and confirm no requests fire when you click Convert.

More XML tooling

Validate, format, or convert XML to other languages — every tool runs locally in your browser.

Frequently Asked Questions

How are XML attributes represented in the interface?

Attributes are emitted as string-literal keys with the prefix "@_" — for example "@_id": string. This matches the default convention of fast-xml-parser (attributeNamePrefix: "@_"). Because the @ character is not a valid bare identifier in TypeScript, the key must be quoted, which also visually separates attributes from element children when reading the interface.

What about namespaces — how are they shown?

fast-xml-parser preserves the prefix in the key by default (e.g. "ex:book"). The basic generator strips the prefix; if you need it, set removeNSPrefix: false in the parser options and rewrite the matching property keys with their prefix as a string literal: "ex:book": Book.

Is this compatible with fast-xml-parser?

Yes. The shape mirrors fast-xml-parser default options: attribute keys prefixed with @_, repeated elements as arrays, and text content under #text when an element has both text and attributes. Cast the parsed result with const data = parser.parse(xml) as Root.

Or xml2js — does the same interface work?

No. xml2js wraps every value in an array by default and puts attributes under a $ property: { book: [{ $: { id: "bk101" }, title: ["..."] }] }. Use a different generator preset, or post-process the xml2js output to flatten arrays before casting to a fast-xml-parser-shaped interface.

How are repeated elements like <tag> in <tags> represented?

Repeated child elements become a Tag[] array property. fast-xml-parser auto-detects arrays for repeated keys; for single-element-or-array ambiguity, configure isArray: (name) => ["tag"].includes(name) so the array is always present.

Can elements with attributes and text content be modeled?

Yes. <price currency="USD">39.99</price> generates a Price interface with two properties — "@_currency": string for the attribute and "#text": number for the text body. fast-xml-parser populates both when textNodeName is left at its default.

Is the XML I paste sent to your servers?

No. XML is parsed by the browser DOMParser and the TypeScript code is generated entirely in JavaScript on your machine. Open DevTools → Network and you will see no requests when you click Convert. Safe for SOAP responses and configuration files containing API keys or credentials.

How do I parse XML and cast to the generated interface?

With fast-xml-parser: import { XMLParser } from "fast-xml-parser"; const parser = new XMLParser({ ignoreAttributes: false }); const data = parser.parse(xml) as Root; — TypeScript now type-checks every access into the parsed object. The ignoreAttributes: false flag is required for attributes to appear as @_-prefixed keys.

XML to TypeScript Converter — Generate Interfaces