billstclair/elm-xml-eeue56/1.0.1

NOTE: the latest version is 3.1.1

Xml.Query

Search the parsed XML

tags : String -> Value -> List Value

Search an XML value for any tags matching

import Xml exposing (Value(..))
import Xml.Encode exposing (object, null, encode)
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 Dict
import Xml 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

import Dict
import Xml exposing (Value(..))


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

import Xml exposing (Value(..))


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

import Xml exposing (Value(..))


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

import Xml exposing (Value(..))


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

import Xml exposing (Value(..))


bool (BoolNode True)
--> Ok True


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