About XML to Kotlin Class
Paste your XML and get Kotlin data class definitions. Supports basic data classes and @Serializable annotated classes for kotlinx.serialization.
Frequently Asked Questions
What is XML to Kotlin data class generation?
XML to Kotlin data class generation analyses an XML document and produces Kotlin data class definitions that model its element and attribute structure. The generated classes are compatible with kotlinx.serialization and JAXB, making XML data accessible in Kotlin projects.
Should I use JAXB or SimpleXML for XML parsing in Kotlin?
SimpleXML (or its successor Simple-XML-Serialization) uses annotations similar to the generated data classes and is simpler for Android. JAXB is the standard for JVM/Spring Boot applications. For modern Kotlin, consider kotlinx.serialization with a custom XML format plugin. The generated data classes work as a structural guide for any library.
How are XML attributes represented in the generated Kotlin data class?
Attributes become properties annotated with @Attribute (SimpleXML) or @JacksonXmlProperty(isAttribute = true) (Jackson XML). The generator uses a conventional @- prefix in property names as a placeholder — rename these to match your chosen XML library's annotation model before compiling.
Can the generated Kotlin data class deserialize XML using kotlinx.serialization?
kotlinx.serialization supports XML via the kotlinx-serialization-xml community library. The generated class provides the property structure; add @Serializable and configure the XML decoder with the appropriate attribute/element annotations. Official XML support is not yet in the core kotlinx.serialization release.
How does the generator handle XML elements with both attributes and text content?
Elements with text content and attributes get a content or _text property for the text plus individual attribute properties. This is the mixed-content model. In Kotlin data classes this becomes: data class Element(val _text: String, @Attribute val id: String). Rename _text to a domain-meaningful name after generation.
Advertisement300 × 250
Advertisement300 × 250