XML to Elm Converter Online

Paste any XML and generate Elm type alias records with String, Int, Float, Bool, and List fields — ready to populate via jinjor/elm-xml-parser. Attributes use an Attr suffix so they never collide with same-named child elements.

What is an XML to Elm converter?

An XML to Elm converter takes a real XML document and emits Elm type alias records that mirror the XML element / attribute tree. The OpenFormatter generator infers Elm types (String, Int, Float, Bool, List a) and produces a complete record hierarchy — ready to populate via jinjor/elm-xml-parser or eeue56/elm-xml-decode.

XML differs from JSON in two ways your Elm record has to honour. First, XML has attributes on elements (<book id="bk101">) — these are read from the Attribute list inside the Element ADT constructor, not by walking children. The generator suffixes attribute fields with Attr to keep the namespace clean. Second, XML allows arbitrary repetition; the generator emits List T for repeated children.

Sample XML and the Elm record it generates

Input XML

<book id="bk101" lang="en">
  <title>Programming Elm</title>
  <year>2019</year>
  <price currency="USD">29.99</price>
</book>

Generated Elm

module Generated exposing (..)

import XmlParser exposing (Xml, Node(..), Attribute)


type alias Price =
  { currencyAttr : String
  , text : Float
  }


type alias Book =
  { idAttr : String
  , langAttr : String
  , title : String
  , year : Int
  , price : Price
  }

Notice idAttr and langAttr carry the Attr suffix because they came from XML attributes. The nested <price currency="USD">29.99</price> generates a Price record with one attribute and one text-content field — exactly what elm-xml-parser exposes via the Element constructor.

How to convert XML to Elm — 4 steps

  1. Paste your XML. A SOAP envelope body, an RSS feed entry, an enterprise XML response — anything well-formed.
  2. Click Convert. The browser parses the XML and generates Elm record type aliases for the full element tree.
  3. Wrap optionals in Maybe. Mark fields that can be absent as Maybe T; the generator stays neutral.
  4. Write the elm-xml-parser decoder. Use XmlParser.parse + a recursive walker to populate the generated record from the Xml ADT.

Pure Records

Every field is a plain Elm record member — no opaque types, no phantom types — so the data is trivial to pattern-match in your update / view functions.

Attribute Suffix

Attribute fields end in Attr so they never collide with same-named children — read from the Element constructor (its Attribute list) during decoding.

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 Elm records from a SOAP service response
  • check_circleBuild Elm models for an RSS or Atom feed reader SPA
  • check_circleConvert configuration XML to typed Elm records in a desktop Elm app
  • check_circleGenerate Elm types from an XSD-described XML file
  • check_circleCreate Elm decoders for legacy enterprise XML in a port-driven SPA
  • check_circleBuild typed records for SAML or WS-Security XML payloads
  • check_circleGenerate Elm models for sitemap.xml or robots.xml
  • check_circleConvert plist XML to typed records for an Elm-driven dev tool

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 Elm source 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

How do you parse XML in Elm?

Elm has no built-in XML parser — the standard library covers JSON via Json.Decode but not XML. The community choice is jinjor/elm-xml-parser which exposes XmlParser.parse : String -> Result Error Xml and a Node ADT (Element name attrs children | Text str). For SOAP-heavy projects, eeue56/elm-xml-decode adds combinators inspired by elm/json. The generator produces records that fit both patterns.

How are XML attributes mapped to Elm record fields?

Attribute fields are suffixed with "Attr" — e.g. <book id="bk101"> becomes idAttr : String — to disambiguate from a sibling child element that might share the name. When you write the XmlParser decoder, you read attributes from the Element constructor (the List Attribute) — second argument (the List Attribute) rather than walking children.

Why is Elm strict about decoders?

Elm has no exception system — every parser failure is a Result Error a value the call site must handle. This makes XML parsing verbose but catastrophically robust: malformed XML or missing fields cannot crash the runtime, they can only produce a Result.Err. The generated record type is the success-side payload; you write the matching decoder to populate it.

Are records the right Elm shape for XML?

Yes — XML elements are inherently structural (a fixed bag of attributes plus children) which matches Elm records perfectly. Custom union types are reserved for genuinely sum-typed XML (e.g. <message>...</message> | <error>...</error>). The generator always emits records; refactor to a union type only when your XML schema exposes alternatives.

How are repeated elements like <tag> typed?

Repeated child elements become List T fields — Elm lists are immutable and ordered, matching XML element ordering. The generator infers T from the first occurrence; if your real data has heterogeneous shapes across instances, define a custom union type and refine the decoder manually.

Does the generator emit a working decoder?

No — it emits the type aliases only, with the elm-xml-parser import scaffold in place. Writing the decoder is the next step: walk the Xml ADT in xmlToBook : Xml -> Result String Book, picking attributes from the Element constructor — its attribute list and recursing into children. The generated record gives you the target shape; the decoder is yours to write.

Is the XML I paste sent to your servers?

No. XML is parsed by the browser DOMParser and the Elm source is generated entirely in JavaScript on your machine. Open DevTools → Network and you will see no requests when you click Convert. Safe for SOAP responses and configuration files containing API keys or credentials.

Why no Maybe wrappers in the output?

Optional-vs-required is a domain decision the generator cannot infer from a single sample. Wrap any field that may be missing in Maybe yourself: title : Maybe String — the decoder would then return Nothing when the XML lacks that element. The generator stays neutral so you do not over-Maybe types that turn out to be required in production.

XML to Elm Converter Online — Free Record Generator