XML to C# Converter
Convert XML to C# classes and POCOs free in your browser.
XML Input
C# Output
What Is XML to C#?
Writing C# POCOs by hand for every XML schema is the kind of work nobody enjoys — especially when the XML comes from a SOAP API with 30 nested elements. C# gives you XmlSerializer for strongly-typed deserialization and XDocument for dynamic parsing. Paste your XML here and get typed POCOs back in seconds. The W3C XML specification defines the input format; everything runs in your browser via DOMParser.
Conversion runs in your browser. You can set the class name, use properties, and nullable types. Nothing is sent to a server. Add XmlElement or XmlAttribute attributes as needed for XmlSerializer.
When XML to C# Helps
When building .NET or ASP.NET Core apps that consume SOAP, RSS, or XML APIs, generate POCOs here. Use XmlSerializer or XDocument to parse. The W3C XML spec defines the format.
How to Use This Tool
Paste or Upload XML
Paste your XML into the left editor or upload a file. Use the config panel to set the root Class Name, Use Properties, and Nullable Types. The more representative your sample, the better the generated structure.
Review the C# Output
The right panel shows generated C# classes. Add XmlElement, XmlAttribute, or XmlRoot attributes as needed. Use XmlSerializer.Deserialize() to parse XML into these types.
Copy or Download
Use Copy or Download to save the classes. For JSON to C#, use JSON to C#. For XML formatting, use XML Formatter.
XML to C# Examples
Here is an example of generating C# classes from XML.
Example: Subscriber record
XML input:
Generated C# output:
When XML to C# Helps
Use this tool when integrating SOAP or REST APIs that return XML, when parsing config files like app.config or web.config, or when building .NET apps that consume XML feeds. Manually writing POCOs for complex XML is tedious; this tool gives you a starting point. Add serialization attributes and adjust types for your XmlSerializer setup.
Frequently Asked Questions
XmlSerializer vs XDocument — which should I use?
XmlSerializer needs POCOs with attributes for strongly-typed deserialization — great when you know the schema. XDocument is for dynamic, schema-free parsing. This tool generates POCOs for XmlSerializer.
How do I deserialize XML into my generated C# class?
Use XmlSerializer.Deserialize() with a StringReader wrapping your XML string. Decorate the class with [XmlRoot] and properties with [XmlElement] or [XmlAttribute] as needed.
Does this work with SOAP XML responses?
Yes. Paste the body element of the SOAP response. The tool generates POCOs for it. For full SOAP client support, consider .NET WCF or a SOAP library.
Is my XML data sent to a server?
No. Class generation runs entirely in your browser. Nothing is uploaded or stored anywhere.
Can I add nullable types to the generated classes?
Yes. Enable Nullable Types in the config panel before converting. This adds ? to value types for optional XML elements.
Related Tools
For XmlSerializer, see Microsoft XML serialization and System.Xml.Linq. For XML, see the W3C XML specification and W3C XML. For parsing in the browser, see MDN DOMParser. For .NET, see .NET. For JSON, see json.org.