XML to Crystal Converter

Generate Crystal classes from XML samples when your service, CLI, or ingestion job still works with XML feeds and wants readable typed transport models.

How to use

  1. Paste a representative XML document that matches the partner feed, import file, or API response your Crystal code still parses.
  2. Review the generated classes, nested child types, and collection fields inferred from repeated XML nodes.
  3. Copy the output into your Crystal project and refine nilable fields, namespaces, or parser integration where production code needs it.

Benefits

  • Produces readable typed Crystal transport models for XML-backed services and tools.
  • Keeps XML feed structure explicit instead of scattering ad hoc hash access across ingest code.
  • Gives Crystal teams a clean first pass before parser-specific annotations or domain wrappers are added.

Best use cases

  • Crystal services that still ingest XML partner feeds or scheduled document exports.
  • CLI tools and background jobs that normalize XML documents into typed transport models.
  • Teams documenting XML-backed integration contracts before finalizing parser and validation layers.

Crystal XML tips

  • Review nilable fields and collection shapes against real XML variability before treating generated classes as stable contracts.
  • Use generated classes as transport models first, then wrap them in richer domain objects if the app needs stricter behavior.
  • Choose the Ruby route only when the target stack is dynamic Ruby rather than compiled Crystal.

Sample XML

<user>
  <id>101</id>
  <name>Ada Lovelace</name>
  <active>true</active>
  <roles>
    <role>admin</role>
    <role>editor</role>
  </roles>
  <profile>
    <email>ada@example.com</email>
    <score>9.8</score>
  </profile>
</user>

Sample output

require "json"

class UserModel
  include JSON::Serializable

  property id : Int32
  property name : String
  property active : Bool
  property roles : Array(String)
end

FAQ

Why use XML to Crystal instead of JSON to Crystal?

Choose XML to Crystal when the source payload is XML and the generated classes need to reflect nested elements, repeated nodes, and document-style structure rather than JSON arrays and objects.

Can nested XML elements become child Crystal model types?

Yes. Nested XML elements are expanded into child classes, and repeated nodes are inferred into collection fields based on the parsed XML sample.