What it does
XML to Code generates classes that read your XML: C# for XmlSerializer, Java with JAXB annotations, Go structs with xml tags, and TypeScript interfaces. Paste a sample document and you get typed classes with the right attributes, elements and lists, plus a usage snippet.
How to use it
- Paste XML, or click Load sample.
- Choose the language.
- Optionally set the namespace (C#), package (Java, Go) or module (TypeScript).
- Copy or download the code. It regenerates as you type.
Example
<order id="1001">
<customer>Ada</customer>
<item sku="X1" qty="2" />
<item sku="Y9" qty="1" />
</order>
Part of the C# output:
[XmlRoot("order")]
public class Order
{
[XmlAttribute("id")]
public int Id { get; set; }
[XmlElement("customer")]
public string Customer { get; set; } = string.Empty;
[XmlElement("item")]
public List<Item> Items { get; set; } = new();
}
How types are inferred
- Repeated elements become lists, with a plural property name (
itembecomesItems). - Missing elements in some records become optional.
- Numbers, booleans and dates are detected from the values: whole numbers become
int(orlongwhen large), decimals becomedecimal, and2026-10-01becomes a date. - XML namespaces are carried into the attributes.
Good to know
- The more complete your sample, the better the classes: include an example of every optional element.
- For SOAP responses, paste the inner payload rather than the whole envelope.
FAQ
Why does Java use Integer rather than int?
Wrapper types can be null, which matches elements that may be missing.
Can I convert the XML to JSON instead? Yes, with the XML to JSON converter.