XML to C#
Turn any XML document into strongly-typed C# classes right in your browser.
Example
Input XML:
<book id="1" pages="320">
<title>Clean Code</title>
<price>44.50</price>
</book>
Generated C#:
public class Root
{
[XmlAttribute("id")]
public int Id { get; set; }
[XmlAttribute("pages")]
public int Pages { get; set; }
[XmlElement("title")]
public string Title { get; set; }
[XmlElement("price")]
public double Price { get; set; }
}How it works
Paste XML and the tool parses it with the browser DOMParser, infers each element/attribute type, and emits PascalCase C# classes (root named Root). Nested elements become nested classes and repeated elements become List<T>.
Good to know
XML to C# takes a raw XML document and generates a set of strongly-typed C# classes (plain POCOs) that mirror its structure, complete with [XmlElement] and [XmlAttribute] attributes so the result is ready to use with System.Xml.Serialization.XmlSerializer. It is aimed at .NET developers who receive XML from a legacy SOAP service, a config file, a partner feed, or an export, and want a typed model to deserialize into instead of poking at XmlDocument nodes by hand.
Reach for it whenever you have a concrete XML sample but no schema (XSD) to run xsd.exe or svcutil against. Paste the XML, click Convert, and you get a Root class plus a separate class for each distinct nested shape. The tool reads each value to guess a type: true/false becomes bool, whole numbers become int (or long when they exceed the 32-bit range), decimal or scientific-notation numbers become double, and everything else stays string. Element and attribute names are converted to PascalCase, while the original XML name is preserved inside the serialization attribute so round-tripping still works.
To read the output: properties carrying [XmlAttribute("...")] map to XML attributes and [XmlElement("...")] map to child elements; any property typed as List<T> means the tool saw that element repeat under the same parent and merged the types across every occurrence into one class. Because the guess is based only on the sample you paste, feed it XML that covers your edge cases — include rows with empty, missing, or unusually large values so a field that should be string or long is not narrowed to int from a single tidy example.
A couple of practical caveats: the generated types use non-nullable value types, so genuinely optional numeric or boolean fields may need to be changed to nullable (int?, bool?) by hand, and the inferred double for money is convenient but you will usually want decimal for currency. The tool runs entirely in your browser via the built-in DOMParser, so nothing is uploaded and it keeps working offline once the page has loaded.
Frequently asked questions
How are repeated XML elements handled?
When an element appears more than once under the same parent, it is emitted as a Listand a dedicated class is generated for its shape, merging types across all occurrences.
How are types inferred from XML text?
Element text and attribute values are pattern-matched: true/false become bool, whole numbers become int (or long if large), decimals become double, and anything else falls back to string.
Is my data uploaded anywhere?
No — this tool runs entirely in your browser. Your input never leaves your device and it works offline once loaded.
Is it free?
Yes, completely free with no sign-up and no limits.
People also ask
Can I generate C# classes from XML without an XSD schema?
Yes. This tool infers the class structure and property types directly from a sample XML document, so you do not need a schema file. It is a practical alternative when you only have example XML and cannot run schema-based generators like xsd.exe.
How is this different from using xsd.exe or svcutil?
xsd.exe and svcutil generate classes from an XSD or WSDL contract, while this tool works straight from a raw XML sample with no schema required. The trade-off is that types here are guessed from the values present in your sample rather than declared in a contract.
Can I deserialize XML into the generated classes with XmlSerializer?
Yes. The classes include System.Xml.Serialization attributes such as [XmlElement] and [XmlAttribute] and a using directive for that namespace, so you can pass them to XmlSerializer to deserialize matching XML into typed objects.
Why did a number in my XML become a string instead of int?
Type inference is pattern-based: only values that match a numeric pattern are typed as int, long, or double. An empty value, a number with surrounding text, leading zeros that look non-numeric, or thousands separators will fall back to string.
Does the generated code handle optional or nullable fields?
It generates non-nullable value types like int and bool based on the sample. If a field can be absent or empty in real data, you typically change it to a nullable type such as int? or bool? after generation.
Why is a price field typed as double instead of decimal?
The tool maps any decimal number to double during inference and does not assume currency semantics. For monetary values, developers commonly switch the property type to decimal manually to avoid floating-point rounding.
What happens if my XML has multiple elements with the same tag name?
When the same element repeats under one parent, it is emitted as a List<T>, and a single class is generated for that element by merging the types seen across all of its occurrences.
Is the XML I paste sent to a server?
No. Parsing and class generation happen entirely in your browser using the built-in DOMParser, so the input stays on your device and the tool functions offline after the page loads.
Related tools