XML Input

Kotlin Output

What the generator writes

Paste an XML sample and you get one Kotlin data class per element name. Attributes and child elements both become val properties, with a comment naming the XML they came from, and text that sits next to attributes becomes a value property.

Repeated elements become List<T> = emptyList(). Properties missing from some records become nullable with a null default, following Kotlin's null safety rules, and a type that contains itself is always nullable. Whole numbers become Int or Long, decimals Double, true/false Boolean. Keywords like class are escaped with backticks.

The classes have no annotations, so they do not bind to XML on their own. With jackson-dataformat-xml you will usually add @JacksonXmlProperty(localName = ...) for renamed fields and @JacksonXmlElementWrapper(useWrapping = false) on repeated ones. Everything runs in your browser; the XML is not uploaded.

How to use it

Paste a sample, adjust the options, copy the classes.

1

Paste a sample

Paste XML into XML Input or Upload a file. Repeated elements need to appear at least twice to become a list. Sample loads a telecom subscriber:

<subscriber id="SUB-1001" active="true">
  <plan>Unlimited 5G</plan>
  <device type="smartphone"><model>Pixel 8</model></device>
  <device type="tablet"><model>iPad Air</model></device>
</subscriber>

Parse errors appear in the output panel. The XML Validator shows the line and column.

2

Set package and options

Root class renames the top-level class (empty uses the root element name). Package sets the package line. Data class switches between data class and a plain class. Nullable for missing fields makes optional properties T? = null; turn it off for non-null properties.

3

Copy or download

Download saves a .kt file named after the root class. Copy puts it on the clipboard.

Where it helps

Android apps on XML APIs

Carrier, banking and travel APIs often still answer in XML. Generated data classes give your repository layer a typed model to map into.

Spring Boot integrations

Paste a partner payload, add the Jackson annotations you need, and you have request and response types for a controller or client.

Replacing manual DOM code

If a codebase pulls values out with getElementsByTagName everywhere, a data class per element is a cleaner target to refactor toward.

Sharing a data contract

A short Kotlin file is easier to review than a long sample document when you agree on a format with another team.

Common questions

Can I deserialize XML straight into these classes?

Not without a library and some annotations. The classes are plain Kotlin. Jackson's XML module or a small hand-written mapper are the usual choices; see the jackson-dataformat-xml README for the annotations.

How are attributes handled?

As ordinary properties, next to the child elements. A comment on each property says whether it came from an attribute, text content or a child element.

How are types inferred?

From every value of that field in your sample. Whole numbers become Int, or Long if they are too big, decimals Double, true/false Boolean. Values with a leading zero stay String, which keeps zip codes intact.

What does the Data class option change?

Only the keyword. With it on you get equals, hashCode, toString and copy; with it off you get a plain class with the same properties.

Why do some names have backticks?

XML names such as class, object or in are Kotlin keywords. Backticks let you keep them as property names.

Is my XML uploaded?

No. It is parsed in your browser. Inputs over 256 KB are rejected; a few representative records are enough.

Related tools

Other converters you might need next: