CalcCafe

XML to Dart

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

Reviewed by the CalcCafe editorial team · Last updated 1 July 2026 · How we test our tools

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.
Is dart easier than Python?
Python is generally easier to start with: dynamic typing, minimal syntax, and an interpreter that runs a single line immediately. Dart is statically typed with C-style braces, semicolons, and sound null safety, which is more to learn up front but catches many errors at compile time and feels familiar to anyone coming from Java, C#, or JavaScript. In practice the choice is driven by purpose, since Dart's main use is building Flutter apps.
What does XML stand for?
XML stands for Extensible Markup Language, a W3C standard published in 1998 for representing structured data as a tree of elements, attributes, and text. Extensible means you define your own tag names, such as <book> and <pages> in the example above, rather than using a fixed vocabulary like HTML. This tool reads that tree and derives a Dart class for each element type.
Is XML still used today?
Yes. XML powers SOAP web services, RSS and Atom feeds, sitemaps, SVG graphics, Android manifests and layout files, Office and OpenDocument formats, build files such as Maven's pom.xml, and countless enterprise integrations. JSON has become the default for new REST APIs, but Flutter and Dart developers still meet XML often enough that typed models like the ones generated here are useful.
Why would you use XML?
XML is a good fit when data needs formal validation against a schema (XSD or DTD), namespaces to mix vocabularies, attributes alongside child elements, comments, or mixed content where text and markup interleave, as in documents. It also has mature standard tooling in XPath, XSLT, and XQuery, and it is required whenever you integrate with SOAP services, feeds, or legacy systems that only speak XML. For simple data exchange between modern services, JSON is usually lighter and easier.

Related calculators

Sources & references

These tools follow our methodology and provide educational estimates only — verify important figures with a qualified professional.