XML decoder, sharing the spirit of Json.Decode.
Using jinjor/elm-xml-parser as its parser component.
eeue56/elm-xml is an existing full-package XML parser/decoder for Elm, though I intend to provide an alternative XML decoder which exhibits following properties:
Decoder-based APIs, sharing the spirit of Json.DecodeJson.Decode.PipelineListDecoder 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)Globally install Elm Platform, elm-test,
and elm-verify-examples
$ elm-test
$ elm-verify-examples
$ elm-verify-examples --elm-test=elm-test # Explicitly set elm-test to use, if particular elm-test version has some issues(Not yet updated for Elm 0.19)
Benchmark codes can be found in benchmarks/ directory.
Using BrianHicks/elm-benchmark and examples in W3School. Available here as a static web page.
Sample result (on my MacBookPro early 2015):

jinjor/elm-xml-parser was using elm-tools/parser, which suffered from some performance issues at that time (possibly related to this comment?).
Although decoding part should practically be fast enough (see decode result of note.xml and cd_catalog.xml).
Looking forward to see similar benchmarks from other related works!!
BSD-3-Clause