EN
My tools

XML to C# Class Generator (XmlSerializer)

Generate C# classes from XML for XmlSerializer: XmlRoot, XmlElement, XmlAttribute and XmlText attributes, List<T> for repeated elements, inferred types.

Otherwise every value is a string.
C# code
Classes generated
3
How to deserialize
needs using System.IO;

XmlSerializer cannot use nullable value types for attributes, so optional numeric, bool or date attributes get a companion …Specified property that tells you whether the attribute was present.

Date-only values (2000-10-01) use DataType = "date" so XmlSerializer reads and writes them without a time.

My tools →
Advertisement

To read XML into objects with .NET's XmlSerializer you need classes whose attributes match the document exactly: [XmlRoot] for the root, [XmlElement] for child elements, [XmlAttribute] for attributes and [XmlText] for text next to attributes. Paste a sample document and get those classes: repeated elements become List<T>, numbers, booleans and dates are typed, optional values are handled the way XmlSerializer requires, and namespaces are carried over.

How to use this tool

  1. Paste a representative XML document — include optional elements and repeats somewhere.
  2. Optionally enter a C# namespace.
  3. Choose whether values are typed (int, decimal, bool, DateTime) or kept as strings.
  4. Copy the classes and deserialize with new XmlSerializer(typeof(Root)).

Formula

root → [XmlRoot] class · attribute → [XmlAttribute] · child element → [XmlElement] · repeated child → List<T> · text beside attributes → [XmlText]

An element with only text becomes a property of a simple type: int or long (by range), decimal, bool (true/false), DateTime (xs:dateTime or xs:date, the latter with DataType = "date") or string; an empty occurrence keeps it string. Elements with attributes or children become classes, shared when their structure is identical. An optional element of a value type becomes T?, while an optional value-type attribute gets a …Specified flag, because XmlSerializer does not support nullable attributes.

Example

The sample catalog gives three classes. Catalog has List<Book> Books ([XmlElement("book")]). Book has Id (string), Available (bool, with AvailableSpecified because only the first book has it), Author, Title, Price, Published (DateTime, DataType = "date") and List<string> Tags. Price has the currency attribute and a decimal [XmlText] Value of 44.95 or 5.95.

Frequently asked questions

Why does a property get a …Specified partner?

XmlSerializer cannot map attributes to nullable types. The Specified pattern is its built-in alternative: the bool tells you whether the attribute was present, and controls whether it is written.

Why is a value typed string instead of int?

At least one sample value is not a plain number, is empty, or starts with a 0 (such as a ZIP code or 007), which a number type would drop. Untick type inference to keep everything as strings, or fix the type by hand.

Does it read XSD files?

No — it infers classes from a sample document. If you have an XSD, Microsoft's xsd.exe or dotnet-xscgen generate classes from the schema itself.

Is my XML uploaded?

No. Generation runs in your browser.

Sources

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). XML to C# Class Generator (XmlSerializer). https://kakao.mobile/tools/xml-to-c-pojo-generator/

MLA

“XML to C# Class Generator (XmlSerializer).” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/xml-to-c-pojo-generator/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement