Elixir to XML Converter

Paste Elixir structs or maps. Get clean XML back.

Input

Output

Paste your Elixir code on the left and press Convert.

Or drop a file on this box, , or .

What this tool does

You are wiring an Elixir app to a legacy SOAP endpoint, or building a fixture for an XML-RPC integration test, and you have the struct but not the envelope. Hand-writing XmlBuilder.element/3 calls for every field gets old fast. Paste the Elixir here (a single %Order{} literal, a defmodule with a defstruct, or a whole file with several modules) and you get well-formed XML back in one pass. Same shape XmlBuilder would build, without the ceremony.

The converter knows Elixir semantics. Atoms lose the leading colon: :is_paid as a map key becomes the element name is_paid, and true / false stay as text. Decimal.new("249.99") drops the wrapper and becomes 249.99. DateTime, NaiveDateTime, and Date come out as ISO-8601 strings. Nested structs (an %Order{} with a shipping_address: %Address{} field) expand in place, and nil values become empty elements instead of being dropped. Keyword lists like [sku: "SKU-101", qty: 2] are treated the same as the equivalent map.

A list field gets a parent element named after the field, and each struct in it becomes a child named after its module, so the sample's items list produces an <items> block with an <OrderItem> per entry. That is the layout SweetXml queries read comfortably, and it is plain enough for the xmerl parser underneath it. Tuples turn into numbered <Item1>, <Item2> children. Several defmodule blocks in one paste are fine, and so is code copied straight out of an .ex or .exs file.

How to use it

Paste the modules, press Convert, copy the XML. A single struct and a full Phoenix context are handled the same way.

1

Paste your Elixir (or try the sample)

Paste Elixir into the left editor: a defstruct, a %Struct{} literal, a plain map, a keyword list or nested structs. Load Sample gives you three small modules and an %Order{} whose amounts are Decimal.new/1 calls.

You do not need to strip @moduledoc, remove @derive annotations, or clean up pipes and comments. Paste the Elixir code the way it looks in your editor.

2

Hit Convert

Press the green Convert button. On the backend, each %Struct{} literal is matched to its defstruct, atoms are turned into text, and one XML document comes back. A "Converting..." overlay covers the editors until it does.

3

Copy the XML

The read-only right pane shows the XML, two-space indented and starting with a declaration line. Copy it into a SOAP body sent with Req or HTTPoison, an XML-RPC call, or a fixture under test/support.

When this actually comes in handy

Phoenix apps talking to SOAP services

Your Phoenix context hands you a nice %Order{}. The downstream vendor only speaks SOAP. Paste the struct, get the XML envelope body, drop it into the request, no hand-crafting XmlBuilder trees.

XML-RPC integrations

Old WordPress plugins, legacy CMS systems, financial feeds: all still speak XML-RPC. Turn your Elixir struct into the <param><value><struct> shape the spec expects, ready to pipe through HTTPoison.

Legacy enterprise integrations

Bank files, EDI feeds, health-care HL7-style payloads. If a partner insists on XML, paste the Elixir model you already have and get a matching XML template: quicker than fighting with xmerl from scratch.

Fixtures for SweetXml round-trips

Writing a test that reads XML with SweetXml and compares it to a struct? Paste the struct, get the XML, save it as a fixture. The round-trip stays consistent.

Common questions

Can I paste multiple defmodule / defstruct blocks at once?

Yes. Paste a whole file. Every defstruct comes through with its fields intact, and nested struct references are expanded. If you include a %Struct{} literal at the bottom with actual values, the output uses those values: otherwise it emits the shape with empty elements.

How are atoms handled?

Atoms used as map/struct keys become element names (the leading colon drops: :is_paid becomes is_paid). Atom values that are booleans (true, false, nil) become the corresponding text. Other atoms are emitted as text with the colon stripped (:pending becomes pending). If you need the original atom syntax, post-process with String.to_atom/1 after parsing.

What about Decimal, DateTime, Date, NaiveDateTime?

Decimal.new("249.99") loses the call and leaves 249.99. DateTime, NaiveDateTime and Date are written as ISO-8601, and Time as HH:MM:SS. A field holding nil keeps its tag with nothing inside, so a SweetXml xpath query for it returns an empty value instead of failing to match.

How do lists, tuples, and keyword lists translate?

A list field becomes a parent element named after the field. Structs inside it become children named after their module (items: [%OrderItem{}, ...] gives <OrderItem> children under <items>), while scalars get a generic child tag. A tuple like {:ok, 42} becomes <Item1>ok</Item1><Item2>42</Item2>. Keyword lists are read like maps, so every key gets its own child element.

What if my struct uses @derive for Jason / Poison?

The @derive annotation is a compile-time hint for JSON libraries and does not affect XML output. All struct fields are emitted by default. If you want to omit a field, remove it from the defstruct list before pasting, or wrap the value in something the converter can recognize as "skip".

Is my code stored?

Each press of Convert posts your Elixir to the backend and gets XML back. The code is not saved anywhere along the way, and reloading the page clears it. Values pulled from config/runtime.exs or System.get_env/1 calls are worth swapping for placeholders before you paste.

Other tools you may need

After converting Elixir structs, you may want to validate the XML, compare it with the JSON form of the same struct, or reformat it. These pages do that: