xmleam/xml_builder
Goals for this module:
- make xml like the string_builder ie. xml_builder.new() |> xml_builder.block_tag(“name”, { xml_builder.new() |> xml_builder.tag(“hello”, “world”) |> xml_builder.tag(“maybe”, “here”)}) |> xml_builder.option_tag(“link”, Opt.(“href”, “https://example.com”)) To:
Types
pub type BuilderError {
ContentsEmpty
LabelEmpty
OptionsEmpty
VersionEmpty
EncodingEmpty
TagPlacedBeforeNew
InnerEmpty
EmptyDocument
NOTAPPLICABLE
}
Constructors
-
ContentsEmpty
-
LabelEmpty
-
OptionsEmpty
-
VersionEmpty
-
EncodingEmpty
-
TagPlacedBeforeNew
-
InnerEmpty
-
EmptyDocument
-
NOTAPPLICABLE
pub type Option {
Opt(label: String, value: String)
}
Constructors
-
Opt(label: String, value: String)
pub type XmlBuilder =
Result(string_builder.StringBuilder, BuilderError)
Functions
pub fn block_tag(
document: Result(StringBuilder, BuilderError),
label: String,
inner: Result(StringBuilder, BuilderError),
) -> Result(StringBuilder, BuilderError)
this starts a block which is a tag with other tags inside of it
ie.
Usage: |>block_tag(“owner”, { new() |> tag(“email”, “example@example.com”) })
pub fn end_xml(
document: Result(StringBuilder, BuilderError),
) -> Result(String, BuilderError)
this one ends the xml document takes in the Xml Document and outputs a Result(String, BuilderError)
pub fn new() -> Result(StringBuilder, BuilderError)
this function starts the blocks inside of tags because of the requirement of document and not having be optional
pub fn new_advanced_document(
version: String,
encoding: String,
) -> Result(StringBuilder, BuilderError)
this funcion starts the builder and allows you to put in your own version and encoding
pub fn new_document() -> Result(StringBuilder, BuilderError)
this function starts the builder and this function assumes version 1.0 and encoding UTF-8 if you need specific verisons or encoding use new_advanced_document(version, encoding)
pub fn option_block_tag(
document: Result(StringBuilder, BuilderError),
label: String,
options: List(Option),
inner: Result(StringBuilder, BuilderError),
) -> Result(StringBuilder, BuilderError)
This is a block tag that has options
pub fn option_content_tag(
document: Result(StringBuilder, BuilderError),
label: String,
options: List(Option),
contents: String,
) -> Result(StringBuilder, BuilderError)
This is for a tag with options and content
ie.
pub fn option_tag(
document: Result(StringBuilder, BuilderError),
label: String,
options: List(Option),
) -> Result(StringBuilder, BuilderError)
This is a tag with options that self-closes ie.
pub fn tag(
document: Result(StringBuilder, BuilderError),
label: String,
contents: String,
) -> Result(StringBuilder, BuilderError)
this is a basic tag that takes in a label and contents and a document in the form of an XmlBuilder this is intended to be used in a pipe chain ie. new_document() |> tag(“hello”, “world”) Throws an error if anything is left blank