XML to C# Converter Online — Generate POCO Classes

Paste any XML and generate XmlSerializer-ready POCO classes. Attributes map to [XmlAttribute], elements to [XmlElement], and nested structures get their own classes — all in your browser.

What is an XML to C# converter?

An XML to C# converter takes a real XML document and emits annotated POCO classes that XmlSerializer can deserialize into. The OpenFormatter generator inspects every element and attribute, infers C# types, and produces a complete class hierarchy with [XmlRoot], [XmlElement], and [XmlAttribute] attributes — saving the tedious step of writing them by hand for SOAP, RSS, or app.config-style XML.

XML differs from JSON in two ways your C# model has to honour. First, XML has attributes on elements (<book id="bk101">) — these become [XmlAttribute]-annotated properties, not [XmlElement]. Second, XML has namespaces; the generator strips them by default, but you can re-add them via the Namespace argument on each annotation. Both aspects are handled by the sample below.

Sample XML and the C# POCO it generates

Input XML

<book id="bk101" lang="en">
  <title>Programming C# 10</title>
  <year>2022</year>
  <price currency="USD">59.99</price>
</book>

Generated C#

[XmlRoot("book")]
public class Book
{
    [XmlAttribute("id")]
    public string Id { get; set; }
    [XmlAttribute("lang")]
    public string Lang { get; set; }
    [XmlElement("title")]
    public string Title { get; set; }
    [XmlElement("year")]
    public int Year { get; set; }
    [XmlElement("price")]
    public Price Price { get; set; }
}

Notice id and lang use [XmlAttribute], while title and year use [XmlElement]. The nested <price currency="USD">59.99</price> generates a Price class with one [XmlAttribute] and one [XmlText] for the text content — exactly what XmlSerializer expects.

How to convert XML to C# — 4 steps

  1. Paste your XML. A SOAP envelope body, an RSS feed entry, an app.config fragment — anything well-formed.
  2. Click Convert. The browser parses the XML and generates XmlSerializer-annotated POCO classes for the full element tree.
  3. Review attribute mapping. Confirm [XmlAttribute] matches the attributes you care about; tweak property names if needed.
  4. Drop into your project. Copy the output, save each class as its own .cs file, and deserialize real XML with new XmlSerializer(typeof(Root)).Deserialize(reader).

XmlSerializer Ready

Generates [XmlRoot] on the top class plus [XmlElement] and [XmlAttribute] on every property — ready to deserialize with new XmlSerializer(typeof(Root)).

Attribute vs Element

XML attributes become [XmlAttribute] properties, child elements become [XmlElement] properties. The distinction is preserved exactly so round-tripping is lossless.

Client-Side Only

Your XML — including SOAP responses with credentials — is parsed in JavaScript on your machine. Verify in DevTools: zero network requests on Convert.

Common use cases

  • check_circleGenerate POCO classes for a SOAP service response
  • check_circleBuild C# models for an RSS or Atom feed reader
  • check_circleConvert app.config or web.config XML into typed POCOs
  • check_circleGenerate C# types from an XSD-described XML file
  • check_circleCreate deserialization models for legacy enterprise XML
  • check_circleBuild typed POCOs for a SAML or WS-Security XML payload
  • check_circleGenerate C# models for sitemaps.xml or robots.xml
  • check_circleCreate POCOs for MSBuild project (.csproj) or NuGet (.nuspec) files

Why client-side conversion matters

SOAP responses and enterprise XML often contain customer PII, API tokens, internal endpoint names, and database identifiers. Pasting them into a server-hosted converter is a compliance violation in most regulated industries. OpenFormatter parses the XML and generates C# code entirely in JavaScript on your device — no upload, no logs, no cookies. Open DevTools → Network and confirm no requests fire when you click Convert.

More XML tooling

Validate, format, or convert XML to other languages — every tool runs locally in your browser.

Frequently Asked Questions

Does it use [XmlElement] / [XmlAttribute] for XmlSerializer?

Yes. The generator emits classes annotated with [XmlRoot], [XmlElement("name")], and [XmlAttribute("name")] from System.Xml.Serialization. The classes deserialize directly with new XmlSerializer(typeof(Root)).Deserialize(stream) — no custom converter or reflection setup required.

Or System.Text.Json — can the same class be used?

No. System.Text.Json is JSON-only and ignores XML attributes. For XML use System.Xml.Serialization (XmlSerializer) or System.Xml.Linq (XDocument). If you also need JSON, add [JsonPropertyName] alongside the XML attributes — both serializers will respect their own annotations on the same POCO.

How are XML attributes mapped to C# properties?

XML attributes (e.g. <book id="bk101">) become public properties annotated with [XmlAttribute("id")]. Element children (<title>...</title>) instead receive [XmlElement("title")]. The two annotations tell XmlSerializer exactly where each value lives in the source XML, so round-tripping is lossless.

How are repeated elements like <tag> in <tags> represented?

Repeated child elements become a List<TagType> property on the parent class. XmlSerializer automatically marshals and unmarshals the list against repeated <tag> elements. You can also wrap with [XmlArray("tags")] [XmlArrayItem("tag")] for explicit container/item naming.

What about XML namespaces?

The basic generator strips namespaces. For namespace-aware binding add Namespace = "http://example.com/ns" to each [XmlElement] and [XmlRoot] attribute, or pass an XmlSerializerNamespaces instance to the serializer at runtime so prefixes are emitted on output.

Can elements with both attributes and text content be modeled?

Yes. <price currency="USD">59.99</price> generates a Price class with two properties — Currency annotated with [XmlAttribute("currency")] and a Value field annotated with [XmlText]. XmlSerializer populates the text content into the [XmlText] property while reading the attribute separately.

Is the XML I paste sent to your servers?

No. XML is parsed by the browser DOMParser and the C# code is generated entirely in JavaScript on your machine. Open DevTools → Network and you will see no requests when you click Convert. Safe for SOAP envelopes and configuration containing API keys, connection strings, or secrets.

How do I deserialize XML into the generated POCOs?

Use XmlSerializer: var serializer = new XmlSerializer(typeof(Book)); using var reader = new StringReader(xml); var book = (Book)serializer.Deserialize(reader); — the [XmlElement]/[XmlAttribute]-annotated properties are populated automatically. Works on .NET Framework 4.x, .NET Core, and .NET 6/7/8.

XML to C# Converter Online — Generate POCO Classes