CalcCafe

XML to Flow

Paste any XML document and instantly generate idiomatic Flow type definitions inferred from its structure.

Example

Input XML:

<book id="1" inStock="true">
 <title>Flow Basics</title>
 <pages>240</pages>
 <author>Ada</author>
 <author>Lin</author>
</book>

Generated Flow:

// @flow

export type Root = {
 "@id": number,
 "@inStock": boolean,
 title: string,
 pages: number,
 author: Array<string>,
};

How it works

The tool parses your XML with the browser DOMParser, builds a value tree (attributes become @-prefixed keys, repeated tags become arrays, leaf text is type-inferred), then walks it to emit deduplicated Flow object types with the root named Root.

Good to know

XML to Flow turns a pasted XML document into a set of Flow type definitions, the static type annotations Flow uses to check JavaScript code. It is aimed at front-end and Node developers who consume XML feeds, SOAP responses, RSS, config files, or legacy API payloads and want hand-written-quality Flow types without typing them out by hand. Everything runs in your browser via the built-in DOMParser, so the XML you paste never leaves your machine.

Reach for it whenever you are wiring XML data into a Flow-checked codebase and need a type to annotate the parsed result, or when you want a quick structural snapshot of an unfamiliar XML response. The output is generated live as you type and again when you press Convert, so you can paste, tweak the source, and watch the types update. Use Load sample to see a worked library/book example, then Copy output to drop the result straight into your project.

Read the output top-down: every distinct object shape becomes its own export type, and the document's root element is always emitted as Root. Attributes appear as quoted, @-prefixed fields (such as "@id": number) because @ is not a valid bare identifier. Scalar values are inferred as number, boolean, or string from the text content, and a child tag that repeats under the same parent becomes an Array<...>.

A few practical caveats are worth knowing:

Frequently asked questions

How are XML attributes represented in the Flow types?
Each attribute becomes a field on its element's type, prefixed with @ (for example @id), and the key is quoted since @ is not a valid bare identifier. Its value type is inferred (number, boolean, or string).
How does it decide when an element should be an array?
If a parent element contains the same child tag more than once, that tag is emitted as an Array<...> of the inferred element type. A tag that appears only once becomes a single field, so add at least two repeated elements if you always want an array.
Is my data uploaded anywhere?
No — this tool runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.

People also ask

What is the difference between XML to Flow and XML to TypeScript?
Both infer the same structure from your XML, but they emit different syntax. Flow output uses Flow annotations (with a // @flow header and nullable types like ?string), while a TypeScript converter emits TypeScript interfaces or types meant to be checked by tsc instead of Flow.
Does this tool need an internet connection to convert XML?
No. The conversion logic is plain JavaScript that runs in your browser using the built-in DOMParser, so once the page has loaded it works offline and your XML stays on your device.
How does it choose names for the generated Flow types?
Each object type is named after the element or field it came from, with the first letter capitalized and invalid characters replaced by underscores; the document root is always named Root. If two different shapes would get the same name, a numeric suffix (like Author2) is added to keep them distinct.
Why are some of my fields typed as ?string instead of a real type?
An element with no text and no attributes (an empty or whitespace-only node) cannot be inferred, so it is typed as ?string, meaning a nullable string. Supplying a value in that element will let the tool infer a concrete number, boolean, or string instead.
How are numbers and booleans detected in the XML text?
The tool inspects each element's trimmed text: values exactly matching true or false become boolean, integer and decimal patterns become number, and everything else stays string. Because XML has no native types, this is purely text-based inference.
Can I paste XML with namespaces or comments?
Yes. The browser's XML parser handles comments and namespaced tags, though namespace prefixes will appear as part of the tag and attribute names in the generated type. Comments and processing instructions are ignored since only element nodes, attributes, and text are used.
What happens if my XML is malformed?
The parser reports a parse error and the tool shows an 'Invalid XML' status with the first line of the error instead of producing types. Fix the reported issue (such as an unclosed tag) and the output will regenerate.
Why do I sometimes get a single field instead of an array?
A child tag is only treated as an array when it appears more than once under the same parent. If a tag occurs just once it becomes a single field, so include at least two repeated elements in your sample when you always expect a list.

Related tools