XML to TypeScript interfaces
JavaScript has no single standard way to turn XML into objects, so the shape you get depends on the parser. This XML to TypeScript generator converts your sample with fast-xml-parser, using these settings: attributes are kept without a prefix, element text next to attributes goes into a value property, namespace prefixes are removed, and numbers and booleans are parsed. It then writes TypeScript interfaces for that object shape. If you parse XML the same way in your app, the interfaces match the data exactly.
Example: an Atom feed
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Release notes</title>
<entry>
<id>urn:uuid:1</id>
<title>Version 2.0</title>
<link href="https://example.com/v2" rel="alternate"/>
<updated>2026-06-01T10:00:00Z</updated>
</entry>
<entry>
<id>urn:uuid:2</id>
<title>Version 1.9</title>
<link href="https://example.com/v1-9" rel="alternate"/>
<updated>2026-04-12T09:30:00Z</updated>
</entry>
</feed>
export interface Feed {
title: string;
entry: Entry[];
}
export interface Entry {
id: string;
title: string;
link: Link;
updated: Date;
}
export interface Link {
href: string;
rel: string;
}
The xmlns declaration is dropped, the two <entry> elements become an array, and <link>, which carries only attributes, becomes an object with href and rel.
Parsing XML to match the interfaces
import { XMLParser } from "fast-xml-parser";
const parser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: "",
textNodeName: "value",
removeNSPrefix: true,
isArray: (name) => name === "entry", // always an array, even with one entry
});
const feed = parser.parse(xmlText).feed as Feed;
The isArray callback matters: without it, a feed with a single entry parses as an object instead of an array, and your code breaks on the first quiet week. The same reason is why your sample should contain at least two of every repeating element. In the browser, DOMParser is an alternative, but then you read values with querySelector and getAttribute and build objects yourself.
Things to adjust
updatedis typedDate, but a parser returns a string; change it tostringunless you convert it.- Numeric-looking IDs lose leading zeros when parsed as numbers; disable number parsing for those tags or type them as strings.
- An element that appears once in some documents and several times in others is typed as a union like
string[] | string; normalize it withisArrayand simplify the type.
To see the JSON produced from your XML, use XML to JSON. For RSS feeds, RSS to JSON is a quick preview. Format the output with the TypeScript Formatter. Generation runs in your browser.