This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
Extend eeue56/elm-xml to simplify building Decoders for XML input.
version 2.1.0
license MIT
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.1.0
Committed At 2017-11-28 11:54:05 UTC
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.1.1 <= v < 6.0.0 5.1.1
eeue56/elm-xml 2.2.2 <= v < 3.0.0 2.2.3



The billstclair/elm-xml-extra package is an extension of the eeue56/elm-xml package that simplifies creating Decoders for XML it parses.

Build Status

Given these definitions:

import Json.Decoder as JD exposing ( Decoder )
import Xml.Extra exposing ( decodeXml )

type alias Person =
    { name : String
    , age : Int

personDecoder : Decoder Person
personDecoder =
    JD.map2 Person
        (JD.field "name" JD.string)
        (JD.field "age"

personTagSpecs : List TagSpec
personTagSpecs =
    [ ("name", Required)
    , ("age", Required)
xml =
<?xml version="1.0" encoding="UTF-8"?>
  <age max="100">50</age>

Here's the code to turn that XML string into a Person object:

decodeXml xml "person" personDecoder personTagSpecs

There's a more complicated example at the top of the documentation for the Xml.Extra module.

If your XML has more than one top-level tag, you can use the other exported functions, which the code for decodeXml should help you understand, to handle it.

There's an example in the example directory.

There are elm-test tests in the tests directory.