dillonkearns/elm-xml-encode/1.0.0

NOTE: the latest version is 1.0.1

Xml.Encode

Use this module for turning your Elm data into an XML string.

encode : Int -> Value -> String

Take a value, then generate a string from it

encodeWith : EncodeSettings -> Int -> Value -> String

Take a value, then generate a string from it

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

Settings used by encodeWith.

  • nullValue: if not omitNullTag, encode a NullNode like this.
  • omitNullTag: if True, omit a tag if it has no attributes and its only content is a NullNode.
defaultEncodeSettings : EncodeSettings

Good default settings for EncodeSettings.

string : String -> Value

Encode a string

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


string "<hello>" |> encode 0
--> "&lt;hello&gt;"
int : Int -> Value

Encode an int

int 15 |> encode 0
--> "15"
float : Float -> Value

Encode a float

float 1.576 |> encode 0
--> "1.576"
bool : Bool -> Value

Encode a bool

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


bool True |> encode 0
--> "true"
object : List ( String, Dict String Value, Value ) -> Value

Encode an "object" (a tag)

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

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

import Dict

Empty contents

null |> encode 0
--> ""
list : List Value -> Value

Encode a list of nodes, e.g

import Dict


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

Encode content as CDATA (Character Data) for embedding HTML or other XML content

cdata "<p>This is <strong>bold</strong> text</p>" |> encode 0
--> "<![CDATA[<p>This is <strong>bold</strong> text</p>]]>"
type Value
= Tag String (Dict String Value) Value
| StrNode String
| IntNode Int
| FloatNode Float
| BoolNode Bool
| NullNode
| Object (List Value)
| DocType String (Dict String Value)
| CdataNode String

Representation of the XML tree