← All XML tools
XML Tools

XML → TypeScript / Java / C# Generator

Paste a sample XML document and generate matching TypeScript interfaces, Java classes, or C# classes — with nested types, arrays for repeated elements, and optional fields inferred automatically.

Use the tool ↓
XML input drop a .xml file here 0 chars
TypeScript output 0 chars
Paste an XML document to generate types.

About this tool

This generator reads the structure of an XML document the same way a person would: it looks at which elements repeat (those become arrays), which ones are missing in some instances but not others (those become optional), which values look like numbers, booleans, or dates (those get typed accordingly), and which elements nest inside others (those become their own separate type, referenced from the parent). It's not doing text replacement on your XML — it builds a structural model first, then emits one of three target languages from that same model, which is why nested elements, arrays, and attributes all come out as properly separate, independently named types rather than one flat blob.

What becomes what

XML valueInferred type
15integer
49.99decimal
true / falseboolean
2026-01-15date
2026-01-15T09:30:00ZdateTime
anything elsestring

An attribute on an element becomes a field alongside that element's child-element fields. If an attribute and a child element happen to share the same name (an id attribute next to a <id> child, for instance), the attribute's generated field name gets an Attr suffix so the two don't collide — the underlying XML name used for serialization stays exactly as it was in your document either way.

Language-specific choices

TypeScript generates interface declarations. Dates come through as string (an ISO-8601 value, not a runtime Date object), since that's what actually round-trips through JSON/XML without a parsing step you'd have to add yourself.

Java generates plain POJO classes with private fields and generated getters/setters — no Lombok, no framework assumptions. Optional numeric and boolean fields use boxed wrapper types (Integer, Boolean) instead of primitives, since Java primitives can't represent "missing." Dates map to java.time.LocalDate / LocalDateTime.

C# generates classes with auto-implemented properties ({ get; set; }). Optional value types get a ? nullable suffix (int?, bool?, DateTime?) when the "Nullable optional fields" option is on.

Turning on Serialization attributes adds @XmlElement/@XmlAttribute/@XmlRootElement (Java, JAXB-style) or [XmlElement]/[XmlAttribute]/[XmlRoot] (C#, System.Xml.Serialization) so the generated class can serialize back to XML using each language's standard library, preserving the original element and attribute names even when a different naming convention is applied to the generated field names. TypeScript has no built-in equivalent, so this option has no effect there.

Everything runs locally in your browser using the built-in XML parser; nothing you paste or upload is sent to a server.

How to use it

  1. 01

    Pick a target language

    TypeScript, Java, or C#. Switching languages regenerates instantly from the same parsed structure.

  2. 02

    Set your options

    Naming convention, whether to preserve original XML names, comments, nullable optional fields, and serialization attributes.

  3. 03

    Paste, upload, or drop your XML sample

    Use a representative sample — one with more than one instance of any repeating element gives more accurate optional/array detection.

  4. 04

    Copy or download the generated code

    Copy to your clipboard, or download as a .ts, .java, or .cs file.

Example

XML
<customer id="42">
  <name>Amy Chen</name>
  <email>amy@example.com</email>
  <tags>
    <tag>vip</tag>
    <tag>wholesale</tag>
  </tags>
</customer>
TypeScript
export interface Customer {
  id: number;
  name: string;
  email: string;
  tag: string[];
}

Common use cases

Typing an XML API response

Generate interfaces or classes for a SOAP or legacy XML endpoint you're consuming.

Scaffolding a data model

Turn a sample export file into a starting set of classes instead of writing them by hand.

Cross-language consistency

Generate the same model in TypeScript, Java, and C# for a system with multiple services.

Config file models

Get typed classes for an XML config file so your app can load it with compile-time safety.

Onboarding a new XML format

Quickly see the inferred shape of an unfamiliar XML document as real code.

XML (de)serialization setup

Generate Java/C# classes with serialization attributes ready to plug into JAXB or System.Xml.Serialization.

Limitations

  • Types are inferred from the sample you paste, not from a schema. A field that's always numeric in your sample but could be text elsewhere in the real data won't be flagged — it'll just come out typed as a number.
  • An element with genuinely mixed content (text alongside child elements) doesn't have a clean field-based representation in strongly typed classes; this tool models its child elements and attributes but doesn't separately capture the inline text.
  • TypeScript's Date/date-time values are generated as string, not a parsed date object — you'll typically want to parse them yourself (e.g. new Date(x.releaseDate)) since XML date strings don't parse identically everywhere.
  • Generated Java uses plain JAXB-style annotations, not framework-specific ones (Jackson XML, etc.); adapt the annotations if your project uses a different library.
  • Very large or deeply irregular XML samples may produce a large number of generated types; review the output rather than assuming every field is exactly what you want long-term.

Best practices

  • Use a sample that includes more than one instance of any element that can repeat — a single instance can't tell the generator that a field is actually optional or an array.
  • Turn on "Preserve XML names" if you're going to hand-wire serialization yourself and want the field names to visually match the XML without relying on the serialization attributes.
  • Review generated names for elements with unusual characters (hyphens, leading digits) — they're sanitized into valid identifiers, but double-check they still read naturally in your codebase.
  • Treat the output as a strong starting point, not a final contract — especially for a document format that might evolve, where a real schema (see the XML ↔ XSD tool) is a more durable source of truth.

Frequently asked questions

How does it decide a field is optional or an array?

By comparing multiple instances of the same parent element in your sample. If a child element is missing from at least one instance, its field is marked optional; if it appears more than once in any instance, its field becomes an array.

What happens with deeply nested XML?

Each element that has its own attributes or child elements becomes its own separate type, referenced from its parent — nesting depth isn't limited, though very deep or irregular structures are worth reviewing manually.

Why is a field typed as "string" when I expected a number?

Type inference requires every observed value for that field to match a numeric pattern. If even one instance in your sample has a non-numeric value (including an empty value), the field falls back to string, since that's the type that's always safe.

Can I use different naming conventions per language?

The tool applies one naming convention at a time to the field or property names in whichever language you're currently viewing — C# properties are always PascalCase by convention regardless of the setting, since that's idiomatic C# and matches what { get; set; } auto-properties look like in virtually all real C# code.

What do the serialization attributes actually do?

They tell Java's JAXB or C#'s System.Xml.Serialization namespace which XML element or attribute name a field corresponds to, so the generated class can be serialized back to XML — or deserialized from it — using each language's standard library, even if the field name itself was changed by a naming convention.

Why doesn't TypeScript get serialization attributes?

TypeScript/JavaScript has no built-in XML serialization framework equivalent to JAXB or System.Xml.Serialization, so there's no standard attribute syntax to generate. The interfaces are still fully usable with any XML parsing library you choose.

What happens if an attribute and a child element have the same name?

The generated field for the attribute gets an Attr suffix added to avoid a naming collision with the child element's field. The actual XML attribute name used by serialization attributes is unaffected — it always reflects your original XML.

Does this validate my XML?

It checks that your XML is well-formed enough to parse (a malformed document will show a clear error), but it doesn't validate against a schema. For that, see the XML Formatter & Validator.

Does my XML get uploaded anywhere?

No. Parsing and code generation both happen locally in your browser, including files you upload or drag in. Nothing is sent to a server.

Is there a file size limit?

No hard limit is enforced, but very large or deeply nested files take longer to analyze and may produce a large number of generated types to review.

Related tools