Free XML to Kotlin Data Class Generator
Convert XML to Kotlin data classes for Android and kotlinx.serialization instantly in your browser.
XML Input
Kotlin Output
What Is XML to Kotlin?
Writing Kotlin data classes by hand from XML is tedious — nested elements, optional fields, and mismatched types all create bugs. This tool generates the boilerplate instantly. Kotlin handles XML via XmlPullParser on Android or kotlinx.serialization for multiplatform projects. The W3C XML spec defines the wire format used by SOAP services and legacy feeds. Paste your XML, choose data class or plain class, enable nullable types for optional elements, and copy the output straight into your Android Studio project. Everything runs in your browser — your XML never reaches our servers. For XML reference, see W3C XML; for browser parsing, see MDN DOMParser.
How to Use This Tool
Paste or Upload XML
Paste XML or upload a file. Set class name, package, Data Class, and Nullable Types in the config.
Review Kotlin Output
The right panel shows generated data classes. Use XmlPullParser or a library to parse and populate.
Copy or Download
Use Copy or Download. For JSON to Kotlin, use JSON to Kotlin. For XML formatting, use XML Formatter.
Frequently Asked Questions
Should I use data class or plain class for XML parsing?
Enable Data Class to get a data class with auto-generated equals(), hashCode(), and copy(). This is ideal for most Android use cases. Use a plain class if you need inheritance or custom logic.
How do I parse XML into the generated Kotlin class?
Use Android's XmlPullParser for streaming, or kotlinx.serialization with the XML plugin for annotation-based mapping. The generated field names match your XML element names directly.
Can I use this for SOAP or RSS XML feeds?
Yes. Paste any valid XML — SOAP responses, RSS feeds, Android layout XML, or config files — and the tool generates matching Kotlin data classes you can use immediately.
What does the Nullable Types option do?
When enabled, fields for XML elements that might be absent are typed as nullable (e.g., val name: String?). This prevents null pointer exceptions when parsing XML where some elements are optional.
Is my XML data sent to a server?
No. The entire conversion runs locally in your browser using JavaScript. Your XML never leaves your device — there's no server, no account, and no upload.
When XML to Kotlin Helps
When building Android apps that consume XML APIs or config, generate data classes here. Use XmlPullParser or Moshi to parse.
XML to Kotlin Examples
Here is an example of generating Kotlin data classes from XML.
Example: Subscriber record
XML input:
Generated Kotlin output:
Related Tools
For Kotlin XML parsing, see XmlPullParser and Kotlin docs. For XML, see the W3C XML spec and W3C XML. For parsing in the browser, see MDN DOMParser. For JSON, see json.org.