billstclair/elm-xml-eeue56/1.0.0

NOTE: the latest version is 3.1.1

Xml

The main data structure along with some trivial helpers.

type Value
= Tag String (Dict String Value) Value
| StrNode String
| IntNode Int
| FloatNode Float
| BoolNode Bool
| Object (List Value)
| DocType String (Dict String Value)

Representation of the XML tree

foldl : (Value -> a -> a) -> a -> Value -> a

Standard foldl

map : (Value -> Value) -> Value -> Value
Standard mapping of a value to another value
xmlToJson : Value -> Value

Convert an Xml.Value to a Json.Value

import Dict
import Json.Encode as Json
import Xml exposing (jsonToXml, Value(..))


xmlToJson (StrNode "hello")
--> Json.string "hello"


xmlToJson (IntNode 5)
--> Json.int 5


xmlToJson (FloatNode 5)
--> Json.float 5


xmlToJson (BoolNode True)
--> Json.bool True


xmlToJson (Object [ IntNode 5, BoolNode True ])
--> Json.list identity [Json.int 5, Json.bool True]


xmlToJson (DocType "" Dict.empty)
--> Json.null
jsonToXml : Value -> Value

Convert a Json.Value into an Xml.Value

import Dict
import Json.Encode as Json
import Xml exposing (jsonToXml, Value(..))


jsonToXml (Json.string "hello")
--> StrNode "hello"


jsonToXml (Json.int 5)
--> IntNode 5


jsonToXml (Json.float 10.5)
--> FloatNode 10.5


jsonToXml (Json.bool True)
--> BoolNode True


jsonToXml (Json.object [("name", Json.string "hello")])
--> Object [ Tag "name" Dict.empty (StrNode "hello") ]


jsonToXml (Json.list identity [Json.string "name", Json.string "hello"])
--> Object [ StrNode "name", StrNode "hello" ]