CalcCafe

XML to Dart

Paste XML and get clean, typed Dart classes inferred from the structure.

Example

Given this XML:

<book>
 <title>Dart</title>
 <pages>320</pages>
 <price>29.99</price>
</book>

You get Dart classes:

class Root {
 final String title;
 final int pages;
 final double price;

 Root({
  required this.title,
  required this.pages,
  required this.price,
 });
}

How it works

It parses your XML with the browser's DOMParser, walks the element tree to infer field types (int, double, bool, String, nested classes and lists), and emits idiomatic immutable Dart classes with a root type named Root.

Good to know

XML to Dart turns a sample XML document into a set of immutable Dart data classes, inferring each field's type directly from the values in your markup. It is aimed at Flutter and Dart developers who need to model a legacy SOAP response, an RSS or sitemap feed, a config file, or any XML-based API without hand-writing class boilerplate. The top-level element always becomes a class named Root, with nested elements promoted into their own named classes.

Reach for it when you have a representative XML payload but no schema (or no patience to read one), and you want a quick, typed starting point for parsing. It is also handy for scaffolding: paste one realistic example, get the class shape, then layer in your fromXml factory logic afterward. Because everything runs locally in the browser, you can safely paste internal or sensitive payloads.

To read the output: scalar text values are mapped to int, double, bool, or String by inspecting the actual content, attributes become regular fields with camelCase names, and any element that repeats under the same parent becomes a List<T>. Every field is final and the generated constructor marks them all required, so the classes are immutable by design.

Frequently asked questions

How are repeated XML elements handled?
When an element appears more than once under the same parent (like multipletags), the field is typed as a Dart List of the inferred element class, e.g. List.
Does it infer numeric and boolean types?
Yes. Text values are inspected: whole numbers become int, decimals become double, true/false become bool, and everything else becomes String. Mixed int/double values widen to double.
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

Does the generated Dart code include fromXml or toXml methods?
No. The tool emits the class shape with final fields and a required-argument constructor only. You add the actual parsing and serialization logic yourself, which is why the fields are described as fromXml-friendly rather than fully wired.
How are XML attributes converted to Dart fields?
Attributes on an element become normal fields on that element's class, with the @ prefix stripped and the name converted to camelCase. Their type is inferred from the attribute value the same way element text is, and xmlns namespace declarations are ignored.
What happens to nested XML elements?
An element that contains child elements (or has its own attributes) is treated as a nested object and gets its own Dart class, referenced as a typed field on the parent. The class name is derived from the element's tag name in PascalCase.
Why is the top-level class always called Root?
The tool names the class generated from the document's root element Root regardless of the original tag name, giving every output a predictable entry point. Nested classes keep names based on their own element tags.
How does it decide between int, double, bool, and String?
It inspects the text: whole numbers become int, decimals or scientific notation become double, the literals true and false become bool, and anything else (including empty values) becomes String. If a field shows both int and double values across occurrences, the type widens to double.
Will it handle an XML file with multiple repeated records?
Yes. When the same tag appears more than once under a parent, the field is typed as a List of the inferred element class, and the tool merges the fields seen across all occurrences so the model covers every record.
What if my XML is invalid or malformed?
The tool parses with the browser's DOMParser and shows an error message such as Invalid XML: could not parse input or No root element found instead of producing classes. Fixing the markup and converting again resolves it.
Can I use the output as Dart null-safe code?
The generated fields are non-nullable and required by default, so they assume every value is always present. If a field can be missing in real data, you will need to change its type to nullable (for example String?) and relax the constructor yourself.

Related tools