C# to XML Converter

Paste C# classes or objects. Get clean XML back.

Input

Output

Paste your C# code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

Somebody hands you a WSDL, a legacy app.config or a partner spec, and what you actually have is a C# class. Writing the matching XML yourself means copying out every property and guessing how the serializer would nest things. Paste the class here, optionally with an object initializer that fills it in, and the page returns a full XML document built from it. Without an initializer you still get the skeleton, with defaults such as 0 and false in place of real values.

The output follows the conventions of XmlSerializer rather than a naive text swap. The sample's TotalAmount = 249.99m is written as 249.99 without the m, a DateTime or DateTimeOffset becomes an ISO-8601 timestamp, and a Guid keeps its usual dashed hex form. List<OrderItem> Items produces an <Items> element holding one <OrderItem> per entry, which is the same nesting the framework would produce on Serialize().

Attributes from System.Xml.Serialization change the shape the same way they would at runtime: [XmlRoot] renames the document element, [XmlElement] renames a child, [XmlAttribute] moves a property onto its parent as an attribute, and [XmlIgnore] removes it. On DataContract types, [DataMember(Name = "x")] is used for the element name. [JsonPropertyName] is ignored, because it only matters to System.Text.Json.

How to use it

It takes about ten seconds: paste a class, press Convert, copy the XML. Big model files go through the same way as a single DTO.

1

Paste your C# (or try the sample)

Paste C# into the left editor. A class with an object initializer gives you real values; a bare class definition or a file with several classes gives you a template. Want to see it first? Load Sample fills in an Order with two OrderItem lines and an Address.

using directives, XML doc comments and attributes can stay where they are; there is no need to trim the file down to plain C# syntax first. Methods are skipped, so pasting the whole class is fine.

2

Hit Convert

Press the green Convert button and the C# travels to the backend, where the class graph is worked out, any [Xml*] attributes are applied and the document is assembled. You will see a "Converting..." overlay on top of both editors until it is done.

3

Copy the XML

The XML shows up on the right with a declaration line and two-space indentation, ready for any XML parser. The output panel is read-only, so select it and copy it into your SOAP envelope, a .config file or a test resource.

When this actually comes in handy

Building SOAP / WCF fixtures

You have a C# request contract and need an XML body to drop into SoapUI or Postman. Paste the class, get the XML, move on.

Starting config files

Got a Settings POCO with 40 properties that has to be read from app.config or a custom XML store? Paste the class and you have the full set of keys laid out, with defaults, to edit instead of typing.

Keeping docs in sync

Generate XML examples for a README, API reference, or XSD-backed schema documentation straight from your actual models, so the docs match the code.

Seeding test data

The object initializers you already wrote for xUnit or NUnit can become XML resource files, whether for a WireMock stub, an end-to-end test or an older service that only accepts XML.

Common questions

Can I paste multiple classes at once?

Yes. Put the whole .cs file in. Every top-level class appears, nested types are expanded where they are referenced, and properties inherited from a base class are included on the derived element. If the classes are unrelated, they are wrapped together under a single <Root>.

Does it honour attributes like [XmlElement], [XmlAttribute], and [XmlIgnore]?

Yes. [XmlRoot("x")] renames the root element, [XmlElement("x")] renames a child, [XmlAttribute("x")] emits the property as an attribute on the parent, and [XmlIgnore] drops it entirely. [DataMember(Name="x")] on DataContract classes also renames the element. This matches what XmlSerializer would do.

How does it handle decimal, DateTime, Guid, and nullables?

49.99m loses its suffix and comes out as 49.99; the same goes for f, d and L. Date values of either kind (DateTime, DateTimeOffset) appear in ISO-8601 form, and Guid keeps the familiar dashed 32-digit hex layout. A decimal? or int? that holds null still gets an element, just an empty one, so every Order in a batch has the same children.

What about nested classes, lists, and dictionaries?

Collections such as List<T>, T[] or a HashSet<T> get a wrapper named after the property with one child per entry, named after T. For example List<OrderItem> Items gives an <Items> element holding <OrderItem> children. A Dictionary<string, decimal> becomes an element whose children are <Entry> pairs of key and value. Nested initializers turn into nested elements.

Is my code stored?

Conversion happens on the backend: the C# goes up in one request, the XML comes down, and neither is kept afterwards. If the class names or default values reveal something you would rather not share, rename them before pasting. The XML shape does not depend on the names.

What if the C# has something unusual: methods, delegates, IntPtr?

Methods, delegates, events and IntPtr fields have no sensible XML form, so they become empty elements and the rest of the model converts normally. Real compile errors are a different matter: a missing brace can confuse the conversion, so if the result looks odd, check that the snippet builds in your IDE first.

Other tools you may need

Once you have the XML from your C# model, these pages help you check it, go back to classes or produce JSON for a newer API: