billstclair/elm-xml-extra/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Xml.Extra

Simplify creating Decoders for XML input.

Types

type alias TagSpec =
( String, Required )

A description of one tag to decode: (<tag name>, Required, <tag decoder>)

= Required
| RequiredIgnore
| Optional
| Multiple

For tagDecoder. How to handle a tag.

Required tags error if not there. RequiredIgnore tags must be in the XML, but are not returned. Optional tags will become null if not in the XML. Multiple tags become a list.

Decoders

tagDecoder : Decoder value -> List TagSpec -> Decoder value

Decode the contents of an XML tag with subtags.

Each TagSpec pulls one or more matching tags from the list.

Unspecified tags in the parsed Value are skipped.

You end up with a single JSON object, with the tags as keys, to which you can apply a standard JSON decoder.

optionalTag : String -> Decoder value -> List TagSpec -> Decoder (Maybe value)

A decoder for Optional XML tags

Functions

String
-> String
-> Decoder value
-> List TagSpec
-> Result String value

Decode an XML string containing a single tag into an Elm value.

stringToJson : String -> Result String Value

Decode an XML string into a simplified Json.Encode.Value.

xmlToJson : Value -> Value

Convert the Xml.Value returned by Xml.Decode.decode to a Json.Encode.Value, removing all the attributes.