XML decoder, sharing the spirit of Json.Decode
. Ready for Elm 0.19.
Using miniBill/elm-xml-parser as its parser component, which is based on elm/parser.
eeue56/elm-xml was an existing full-package XML parser/decoder for Elm, though I intended to provide an alternative XML decoder which exhibits following properties:
Decoder
-based APIs, sharing the spirit of Json.Decode
Json.Decode.Pipeline
ListDecoder
typeBasics:
import Xml.Decode exposing (..)
type alias Data =
{ string : String
, integers : List Int
}
dataDecoder : Decoder Data
dataDecoder =
map2 Data
(path [ "path", "to", "string", "value" ] (single string))
(path [ "path", "to", "int", "values" ] (list int))
run dataDecoder
"""
<root>
<path>
<to>
<string>
<value>SomeString</value>
</string>
<int>
<values>1</values>
<values>2</values>
</int>
</to>
</path>
</root>
"""
--> Ok { string = "SomeString", integers = [ 1, 2 ] }
We have map
, map2
and variants, though the Pipeline style is also possible:
pipelineDecoder : Decoder Data
pipelineDecoder =
succeed Data
|> requiredPath [ "path", "to", "string", "value" ] (single string)
|> requiredPath [ "path", "to", "int", "values" ] (list int)
Install reasonably new Node.js (currently Node.js 22 is tested)
npm install
npm test
Benchmark app can be found in benchmarks/
directory.
Using examples in W3School and
elm-explorations/benchmark.
npm run generate-benchmark
# Open docs/index.html
Also available at https://ymtszw.github.io/elm-xml-decode/
It may hang for a while during JIT warming up, but keep waiting (~ a minute).
Sample result (on my Windows 10 machine):
BSD-3-Clause