XML Input

Dart Output

What the generator writes

Flutter apps still run into XML: RSS feeds, SOAP responses, old CMS exports. This page reads an XML sample and writes one Dart class per element name, each with final fields, a named constructor and a factory Article.fromXml(XmlElement element) that reads the values back out using package:xml.

Repeated elements become a List built from findElements, attributes are read with getAttribute, and numbers go through int.tryParse or double.tryParse. The code is null-safe: anything that is missing from some records is nullable when Nullable fields is on, and nested elements that may be absent are always nullable.

Add xml to your pubspec, drop the file in, and call Feed.fromXml(XmlDocument.parse(body).rootElement). The conversion itself runs in your browser, so the XML you paste stays on your machine. See the Dart docs on factory constructors if you want to extend the generated ones.

How to use it

Paste a sample, check one setting, copy the result.

1

Paste a feed or response

Put XML into XML Input or click Upload. Use a sample that shows repeated items more than once and includes the optional fields. Sample loads a small article feed:

<feed updated="2026-03-02T08:00:00Z">
  <article id="A-1001">
    <title>Shipping Flutter builds faster</title>
    <tag>flutter</tag>
    <tag>ci</tag>
  </article>
</feed>

Errors in the XML show up in the output panel. Check a file first with the XML Validator if you are not sure about it.

2

Choose how missing data is typed

Root class renames the top-level class (empty uses the root element name). With Nullable fields for missing data on, optional values are String?, int? and so on. Turn it off and they fall back to '', 0 or false instead.

3

Copy or download

Download saves a .dart file; Copy puts it on the clipboard. The file only imports package:xml/xml.dart.

Where it helps

RSS and Atom feeds

Paste one feed response and get model classes plus parsing code for the articles list, ready for a ListView.

SOAP and legacy APIs

When a backend only speaks XML, generated fromXml factories save you from writing getElement chains by hand for every screen.

Offline data bundles

Apps that ship XML catalogs or config files in assets can load them straight into typed objects at startup.

Prototyping a model

Even if you later move to JSON, the classes give you a typed starting point while the API is still XML.

Common questions

Which package does the code need?

Only xml from pub.dev (dart pub add xml). It uses getElement, findElements, getAttribute and innerText, which have been part of package:xml 6.x for a long time.

Does it use json_serializable or code generation?

No. The fromXml factories are written out in full, so there is no build_runner step. If you also need JSON, add toJson yourself or annotate the classes later.

How are numbers and booleans detected?

From the values in your sample. Whole numbers become int, decimals double, true/false bool. Values with a leading zero stay String. On Flutter web, keep in mind that an int past 2^53 loses precision, so treat very long IDs as strings.

What if an element is missing at runtime?

Optional nested elements are nullable and come back as null. Required ones use !, so a missing required element throws, which is usually what you want for a broken payload.

Are XML namespaces supported?

Element and attribute lookups use the names exactly as they appear in your sample, prefix included (getElement('media:content')). That works as long as the documents you parse use the same prefixes.

Is my XML uploaded?

No. Everything runs in your browser. Inputs over 256 KB are rejected; a sample with a few records is all the generator needs.

Related tools

Other tools for working with XML and Dart: