billstclair / elm-xml-eeue56 / Xml.Encode

Use this module for turning your Elm data into an Xml representation that can be either queried or decoded, or turned into a string.

encode : Basics.Int -> Xml.Value -> String

Take a value, then generate a string from it

encodeWith : EncodeSettings -> Basics.Int -> Xml.Value -> String

Take a value, then generate a string from it


type alias EncodeSettings =
{ nullValue : String
, trueValue : String
, falseValue : String
, omitNullTag : Basics.Bool
, attributeSingleQuoteInsteadOfDouble : Basics.Bool 
}

Settings used by encodeWith.

defaultEncodeSettings : EncodeSettings

Good default settings for EncodeSettings.

string : String -> Xml.Value

Encode a string

string "hello" |> encode 0
--> "hello"

string "<hello>" |> encode 0
--> "&lt;hello&gt;"

int : Basics.Int -> Xml.Value

Encode an int

int 15 |> encode 0
--> "15"

float : Basics.Float -> Xml.Value

Encode a float

float 1.576 |> encode 0
--> "1.576"

bool : Basics.Bool -> Xml.Value

Encode a bool

bool True |> encode 0
--> "true"

bool True |> encode 0
--> "true"

object : List ( String, Dict String Xml.Value, Xml.Value ) -> Xml.Value

Encode an "object" (a tag)

objectSafe : List ( String, Dict String Xml.Value, Xml.Value ) -> Result String Xml.Value

Encode an "object" (a tag) only allowing valid tag names

import Dict

null : Xml.Value

Empty contents

null |> encode 0
--> ""

list : List Xml.Value -> Xml.Value

Encode a list of nodes, e.g

import Dict

list [ object [ ("Root", Dict.empty, null) ], int 5 ] |> encode 0
--> "<Root></Root>\n5"