Dart to XML Converter
Paste Dart classes or objects. Get clean XML back.
What this tool does
If you have ever had to shape an XML payload to match a Dart model — for a Flutter app talking to a legacy SOAP endpoint, an Android-style XML config, or an RSS feed reader — you know how much boilerplate that is. Paste the Dart here and the tool returns well-formed XML in one pass. One class with final fields, a full model file, or a populated instance — same outcome: a complete XML document with every field preserved.
It is not naive string-replacement. The converter reads real Dart: named required parameters become elements in declaration order, final fields behave identically to non-final ones, DateTime values render as ISO-8601 strings, Duration uses ISO-8601 duration format, num, int, and double preserve their numeric shape, null (from nullable types like String?) becomes an empty element instead of being dropped, and List<T> becomes a container element with one child per item — matching what the xml package’s XmlBuilder would emit.
Class structure is preserved. Each top-level class becomes a root element named after the class, every field becomes a child element, nested classes expand inline, and Map<K, V> turns into <entry><key/><value/></entry> pairs. Annotations like @JsonKey(name: "x") from json_annotation are honoured as element-renaming hints. Paste a Flutter model, a freezed-style data class, or a plain Dart POJO — the XML looks the way a hand-written XmlBuilder call would produce it, just without the ceremony.
How to use it
Three steps. Same flow whether you paste a single model or an entire <code>lib/models</code> folder.
Paste your Dart (or try the sample)
Drop your Dart into the left editor as-is. A regular class, a named-constructor data class, multiple classes, or a populated instance — all fine. Click Load Sample to see a realistic Order example first.
You do not need to remove imports, strip part directives, or delete annotations. Keep the code as it looks in your IDE. Just paste.
Hit Convert
Click the green Convert button. The tool reads the Dart, keeps every class and field, and builds the XML in one pass. A short shimmer shows while it runs.
Copy the XML
The right panel fills with indented, well-formed XML that any standards-compliant parser will accept. Drop it into a SOAP request, a Flutter asset file, an Android-style config, or a unit-test fixture.
When this actually comes in handy
Flutter apps talking to SOAP services
Your Flutter app has to call a legacy SOAP endpoint and the request body has to match a Dart model. Paste the model, take the XML, feed it to <code>http.post</code> or the <a href="https://pub.dev/packages/xml" target="_blank" rel="noopener">xml</a> package.
RSS and Atom feed generators
Building a podcast or news app that publishes RSS? Paste the episode model, get the XML shape you need, then wrap it with the feed envelope — no hand-counting <code><item></code> children.
Android/iOS native XML configs
Need to produce an Android-style preferences XML or an iOS plist-like structure from a Dart model used in platform channels? Paste the class and get a ready-to-tweak template.
Test fixtures for flutter_test
Turn a populated model into an XML fixture file for <code>flutter_test</code>, widget golden tests, or mock HTTP responses — a faster path than writing fixture strings by hand.
Common questions
Can I paste several classes at once?
Yes — paste a whole models.dart file or a full model folder. Each top-level class comes through with nested classes expanded and fields from parent classes rolled in. Mixins are treated as contributing their fields. Nothing gets silently dropped.
Does it work with freezed or json_serializable data classes?
Yes. Freezed-style immutable classes and json_serializable-annotated models are treated as regular Dart classes — fields come through, @JsonKey(name: "x") is honoured as an element-renaming hint. You do not need to run build_runner or paste the generated .g.dart file.
How are DateTime, Duration, null, and num handled?
DateTime renders as an ISO-8601 string (2026-04-21T10:15:00.000Z). Duration renders as an ISO-8601 duration (PT2H30M) or HH:mm:ss fallback. Nullable types with a null value become empty elements (<field/>) rather than being omitted, so the XML shape stays consistent. num, int, and double all serialize as plain decimal text.
What about List, Map, and nested classes?
List<T> becomes a container element with one child per item, named after the element type — a List<OrderItem> items turns into <items><OrderItem/><OrderItem/></items>. Map<K, V> becomes <entry><key/><value/></entry> pairs. Nested classes expand inline, the same way xml package’s XmlBuilder produces nested elements.
Is my code stored?
Your Dart is sent to the backend for conversion and is not persisted — we do not log the payload. As always with online tools, if the code contains genuinely sensitive literals (API keys, tokens), scrub or mock them before pasting.
What if the class uses dynamic or Object? fields?
Fields typed as dynamic or Object? are serialized as string text based on their assigned literal value, since the actual shape is only known at runtime. If you want stronger XML output, narrow the type (String, int, a concrete class) and the converter will pick up the structure automatically.
Other tools you may need
Dart to XML is one piece of the puzzle. These tools pair well with it: