XML to C# Class Generator
Classes with XmlSerializer attributes, ready to deserialize
XML Input
C# Output
What the generator writes
Paste an XML sample and you get C# classes annotated for XmlSerializer. The root class gets [XmlRoot("order")] with the real root element name, attributes get [XmlAttribute], child elements [XmlElement], and text next to attributes [XmlText].
Repeated elements become List<T> initialised to an empty list, which is how XmlSerializer collects unwrapped repeated elements. Numbers are typed int, long, double or bool from the values you paste. With Nullable for missing fields on, the file starts with #nullable enable, missing elements become int? or string?, and required strings default to string.Empty. The attribute reference explains each annotation.
We compiled the output with .NET 8 and deserialized the page sample with it. Number and boolean attributes stay non-nullable on purpose, because XmlSerializer refuses Nullable<T> on [XmlAttribute]. The XML is processed in your browser and not uploaded.
How to use it
Paste, pick two options, copy.
Paste a sample
Paste XML into XML Input or Upload a file. Repeated elements must appear twice to become a list. Sample loads an order:
<order id="ORD-7731" status="paid">
<item sku="SKU-101"><qty>2</qty><price currency="USD">24.99</price></item>
<item sku="SKU-205"><qty>1</qty><price currency="USD">39.50</price></item>
</order>Parse errors are shown in the output panel. The XML Validator shows where.
Choose properties and nullability
Root class renames the top-level class (empty uses the root element name; the [XmlRoot] name stays the real element name either way). Properties switches between auto-properties and public fields. Nullable for missing fields turns on nullable reference types for the file.
Deserialize
Download the .cs file, then var order = (Order)new XmlSerializer(typeof(Order)).Deserialize(stream);.
Where it helps
SOAP and legacy services
When you have a sample message but no WSDL or XSD, generated classes get you deserializing in minutes.
ASP.NET Core XML endpoints
With AddXmlSerializerFormatters, annotated classes like these work as request and response models.
Config and import files
Read vendor XML exports into typed objects in a background service or console tool.
Unity and desktop apps
XmlSerializer is available in Unity and WPF, so the same classes work for save files and settings.
Common questions
Will XmlSerializer accept these classes as they are?
Yes. Classes are public with public members and an implicit parameterless constructor, which is what XmlSerializer needs. [XmlRoot] uses the actual root element name, so the root does not have to be called RootObject.
How are attributes and text mapped?
Attributes get [XmlAttribute("name")]. If an element has attributes and text, such as <price currency="USD">24.99</price>, the text goes into a Value member with [XmlText].
How are namespaces handled?
Elements and attributes in a namespace get a Namespace = "..." argument with the URI from your sample, and the root gets it on [XmlRoot].
How are types chosen?
From your sample values: whole numbers become int or long, decimals double, true/false bool. Values with a leading zero stay string. Change double to decimal for money if you prefer.
Why is a member called CategoryValue?
C# does not allow a member with the same name as its class, so when an element contains a child of the same name, the member gets a Value suffix. The XML name in the attribute is unchanged.
Is the XML uploaded?
No. It is parsed in your browser. Inputs over 256 KB are rejected.
Related tools
Other converters you might reach for next: