This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
XML parser, encoder/decoder and queries in Elm
version 2.2.3
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 2.2.3
Committed At 2017-12-06 15:28:35 UTC
elm-lang/html 2.0.0 <= v < 3.0.0 2.0.0
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

README

elm-xml Build Status

xml parser for elm

First bring XML into Elm as a Value. Once imported as a Value, you can then either query the values with Xml.Query.

Or you can turn it back to a string using Xml.Encode.encode. Or pull it apart using Xml.Encode.Value.

In order to turn an Xml.Value into a record, you probably want Xml.Query, paired with Result.map.


import Xml exposing (Value)
import Xml.Encode exposing (null)
import Xml.Decode exposing (decode)
import Xml.Query exposing (tags)

decodedXml : Value
decodedXml = 
    """
<person>
    <name>noah</name>
    <age max="100">50</age>
</person>
<person>
    <name>josh</name>
    <age max="100">57</age>
</person>
    """
        |> decode
        |> Result.toMaybe
        |> Maybe.withDefault null


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

person : Value -> Result String Person
person value =
    Result.map2
        (\name age ->
            { name = name
            , age = age
            }
        )
        (tag "name" string value)
        (tag "age" int value)


people : List Person
people =
    tags "person" decodedXml
        |> collect person