eeue56/elm-xml/1.1.0

NOTE: this package is not compatible with Elm 0.19.1

Xml.Query

Search the parsed XML

tags : String -> Value -> List Value

Search an XML value for any tags matching

>>> import Xml.Encode exposing (object, null, encode, Value(Tag, Object))
>>> import Dict
>>> object [ ("name", Dict.empty, null)] |> tags "name"
[Tag "name" Dict.empty (Object []) ]
contains : Value -> Value -> Bool

check if a XML value contains another XML value

tag : String -> (Value -> Result String a) -> Value -> Result String a

Try to get a given tag name out from an XML value, then grab the value from that Grabs the first tag that matches in the object

>>> import Xml.Encode exposing (Value(..))


>>> tag "name" string (Tag "name" Dict.empty (StrNode "noah"))
Ok "noah"


>>> tag "name" string (Tag "name" Dict.empty (IntNode 5))
Err "Not a string."


>>> tag "name" string (StrNode "noah")
Err "No tag called 'name' found."
collect : (Value -> Result String a) -> List Value -> List a

Collect as many values that pass the given converter

>>> collect (tag "name" string) [Tag "name" Dict.empty (StrNode "noah")]
[ "noah" ]


>>> collect (tag "name" string) [Tag "name" Dict.empty (IntNode 5)]
[ ]
default : b -> Result a b -> Result a b
Set a default for a result


>> default "Cat" (Ok "Fish")
Ok "Fish"


>> default "Dog" (Err "flip")
Ok "Dog"
string : Value -> Result String String

Try to turn a value into a string

>>> string (IntNode 5)
Err "Not a string."


>>> string (StrNode "hello")
Ok "hello"
int : Value -> Result String Int

Try to turn a value into an int >>> int (IntNode 5) Ok 5

>>> int (StrNode "hello")
Err "Not an int"
float : Value -> Result String Float

Try to turn a value into an int >>> float (FloatNode 5.5) Ok 5.5

>>> float (StrNode "hello")
Err "Not a float"
bool : Value -> Result String Bool

Try to turn a value into an int >>> bool (BoolNode True) Ok True

>>> bool (StrNode "hello")
Err "Not a bool"