Ruby to XML Converter
Paste Ruby classes or objects. Get clean XML back.
What this tool does
If you have ever had to hand-craft an XML payload to match a Ruby class — maybe for a Rails to_xml fixture, a legacy SOAP call, or a Nokogiri Builder template — you know the boilerplate adds up fast. Paste the Ruby here and the tool gives you back well-formed XML in one pass. One attr_accessor class, a Struct.new, a whole model file, or deeply nested objects — same result: a complete XML document with every field preserved.
It is not just string replacement. The converter understands how Ruby values really serialize: BigDecimal("49.99") comes out as a plain numeric string (no scientific notation), Time and DateTime render as ISO-8601 strings, Symbol values lose the leading colon, nil becomes an empty element instead of being dropped, and arrays become container elements with one child per item — matching what Nokogiri::XML::Builder and Rails to_xml usually produce.
Class structure is honoured too. Each top-level class becomes a root element named after the class (snake-cased), attr_accessor symbols become child elements, nested objects are expanded inline, and arrays of OrderItem turn into an <items> wrapper with one <order_item> child per entry. Hashes get key/value child elements. Inherited attributes come through. If you paste a Rails model or a plain PORO, the result looks like what render xml: or REXML::Document.new (see REXML) would hand you, just without the ceremony.
How to use it
Three steps. Same flow whether you paste a single Struct or a whole lib folder.
Paste your Ruby (or try the sample)
Drop your Ruby into the left editor as-is. An attr_accessor class, a Struct.new shortcut, multiple classes, or a populated instance — all fine. Click Load Sample to see a realistic Order example first.
You do not need to remove require lines, strip modules, or simplify the syntax. Keep the code as it looks in your editor. Just paste.
Hit Convert
Click the green Convert button. The tool reads the Ruby, keeps every class and attribute, and builds the XML in one pass. A short shimmer shows while it runs.
Copy the XML
The right panel fills with indented, well-formed XML that any standards-compliant parser will accept. Drop it into a SOAP request, a fixture file for RSpec, a Rails integration test, or your API docs.
When this actually comes in handy
Building Nokogiri or Builder fixtures
You have a Ruby class and need an XML template for Nokogiri::XML::Builder or an ERB template. Paste the class, take the XML, paste it into your Builder block — done.
Rails to_xml seed data
An ActiveRecord model or PORO with 20 attributes becomes a ready-to-edit XML seed file for your integration tests or an external system that still consumes XML.
Legacy SOAP integrations
A Ruby client talking to an old SOAP/XML-RPC service needs a request body that matches a Ruby class. Paste the model, get the XML envelope shape, stop fighting <a href="https://www.ruby-doc.org/" target="_blank" rel="noopener">Savon</a> templates.
Keeping docs and code in sync
Generate XML response examples for a README, API reference, or XSD-backed documentation straight from the actual Ruby models, so the docs never drift from the code.
Common questions
Can I paste several classes at once?
Yes — paste a whole lib file. Each top-level class comes through with nested classes expanded and superclass attributes rolled in. Mixins are treated as contributing their attr_accessors. Nothing gets silently dropped.
Does Struct.new shorthand work?
Yes. Order = Struct.new(:order_id, :customer_name, :total_amount) is treated the same as a class with matching attr_accessors. Keyword-style structs (Struct.new(:a, keyword_init: true)) work too — the resulting XML is identical either way.
How are BigDecimal, Time, Symbol, and nil handled?
BigDecimal("49.99") becomes the plain string 49.99 (no scientific notation, no trailing bd marker). Time, DateTime, and Date render as ISO-8601 strings. Symbol values lose the colon and become plain text. nil becomes an empty element (<field/>) rather than being dropped, so the XML shape stays consistent.
What about arrays, hashes, and nested objects?
Arrays become container elements — items = [OrderItem.new, OrderItem.new] turns into <items><order_item/><order_item/></items>, one child per entry, named after the element class. Hashes become <entry><key/><value/></entry> pairs. Nested objects are expanded inline as child elements, the same way Rails to_xml handles them.
Is my code stored?
Your code is sent to the backend for conversion and is not persisted — we do not log the payload. As always with online tools, if the Ruby contains genuinely sensitive literals (API keys, customer PII), scrub it before pasting.
What if the code uses metaprogramming or define_method?
Anything that only exists at runtime (methods added via define_method, attributes set through method_missing, mixed-in modules with computed attrs) cannot be inferred from static code alone. The tool reads declared attr_accessor, attr_reader, Struct fields, and explicit assignments. If a field only shows up via metaprogramming, list it as an attr_accessor so the converter can see it.
Other tools you may need
Ruby to XML is one piece of the puzzle. These tools pair well with it: