XML to DTO Generator
Guide: Turn JSON or XML Into Classes (DTOs) in Java, C# and More
Nothing you enter or choose here leaves your device. This tool runs in your browser.
A sample and its classes
Paste an XML document and the tool builds classes for it. Take this order, with an attribute on the root, two items that each carry an attribute and some text, and a total:
<order id="7"><item sku="A1">Pen</item><item sku="B2">Ink</item><total>9.5</total></order>
In TypeScript, you get an Order with an id, a list of Item and a total, and an Item with a sku and a value:
export interface Order {
id: number;
item: Item[];
total: number;
}
export interface Item {
sku: string;
value: string;
}The text inside an element that also has attributes has nowhere else to go, so it becomes a field called value. Attributes and child elements both become fields. With annotations on, each keeps its XML name and kind, such as @XmlAttribute or @XmlElement in Java's JAXB, so the code can read and write the same XML.
The list trap
An element that appears more than once under the same parent becomes a list. An element that appears once becomes a single object. If your sample has one item and the real documents have many, the generated class is wrong. Always include at least two of anything that can repeat.
Numbers and booleans
By default, 42 is read as an integer and true as a boolean, which is why the total above is a number. If some values look numeric but are really codes, such as a postcode of 02134 or a product number, turn off Detect numbers and booleans and every field becomes a string, so leading zeros survive.
| XML feature | Becomes |
|---|---|
| An attribute | A field, marked as an attribute when annotations are on |
| A child element | A field, or its own class if it has children |
| A repeated element | A list |
| Text beside attributes or children | A field named value |
| An empty element | A nullable field |
Languages and serializers
Pick Java for JAXB mappings, C# for XmlSerializer attributes, or TypeScript, Kotlin, Python or Go. Annotations are what make the class round-trip correctly. Without them, you get plain classes that are fine for reading structure but won't match the XML by themselves.
Before you rely on it
- Check optional elements. Anything missing from your sample won't appear in the class.
- Namespaces and mixed content (text with tags in the middle of a paragraph) need hand editing.
- Dates arrive as strings. Change the type if your code expects a date object.
- If a schema file (XSD) exists, a generator that reads it is more complete than one that reads a sample.
The XML is parsed in your browser and nothing is sent. To look at the same data as JSON, use the XML and JSON converter, and for JSON input, the JSON to DTO tool. The guide to JSON and XML formats explains how they compare.
Written by Akinrinmade Michael · Updated October 24, 2026
How to use
- 1Paste an XML document into the input box.
- 2Choose the language and, if you like, a root class name and package.
- 3Turn annotations on to get JAXB, XmlSerializer or Jackson XML mappings.
- 4Click Copy code and paste it into your project.
Frequently asked questions
How are attributes and elements mapped?
Attributes and child elements both become fields, and with annotations on, each keeps its original XML name and kind (for example @XmlAttribute or @XmlElement). Text next to attributes or child elements becomes a field named value.
How does it know when an element is a list?
An element that appears more than once under the same parent becomes a list. If your sample has only one <item>, it is treated as a single object, so include two or more in the sample to get a list.
Does it read numbers and booleans?
Yes, by default, so 42 becomes an integer and true becomes a boolean. Turn off "Detect numbers and booleans" to make every field a string.
Is my XML uploaded anywhere?
No. It is parsed and converted in your browser, and nothing is sent to a server.
Read the guide
Learn how this works and how to get the most from it.
Developer
Turn JSON or XML Into Classes (DTOs) in Java, C# and More
What a DTO is, how generated classes map JSON and XML, and the details to check before you trust a generated model.
3 min read
Related tools
JSON to DTO Generator
Turn JSON into Java, C#, TypeScript, Kotlin, Python or Go classes.
JSON Formatter & Validator
Prettify, minify and validate JSON, with error line numbers.
Text Diff Checker
Compare two texts side by side and see exactly what changed.
Base64 & URL Encoder / Decoder
Encode and decode Base64 and URL-encoded text instantly.