xmleam/xml_builder

Goals for this module:

  1. 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:
world

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_comment(
  document: Result(StringBuilder, BuilderError),
  inner: Result(StringBuilder, BuilderError),
) -> Result(StringBuilder, BuilderError)

This is a funciton for a block comment, works like block_tag but does not take a label

pub fn block_tag(
  document: Result(StringBuilder, BuilderError),
  label: String,
  inner: Result(StringBuilder, BuilderError),
) -> Result(StringBuilder, BuilderError)

Starts a block which is a tag with other tags inside of it ie. example@example.com

Usage: |>block_tag(“owner”, { new() |> tag(“email”, “example@example.com”) })

pub fn cdata_tag(
  document: Result(StringBuilder, BuilderError),
  label: String,
  contents: String,
) -> Result(StringBuilder, BuilderError)

this is a basic tag that automatically adds the CDATA tag to the XML NOTE: This same effect can be created with any other tag by adding

to the content blocks, this is just for convienence
pub fn comment(
  document: Result(StringBuilder, BuilderError),
  comment: String,
) -> Result(StringBuilder, BuilderError)

This a comment function, works the same way as any other tag But makes whatever you put in as a string a comment

pub fn end_xml(
  document: Result(StringBuilder, BuilderError),
) -> Result(String, BuilderError)

Ends the XML document takes in the XML Document and outputs a Result(String, BuilderError)

pub fn new() -> Result(StringBuilder, BuilderError)

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)

starts the builder and allows you to put in your own version and encoding

pub fn new_document() -> Result(StringBuilder, BuilderError)

starts the builder and 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)

block tag that also has options

pub fn option_content_tag(
  document: Result(StringBuilder, BuilderError),
  label: String,
  options: List(Option),
  contents: String,
) -> Result(StringBuilder, BuilderError)

Tag with options and content ie. ??

pub fn option_tag(
  document: Result(StringBuilder, BuilderError),
  label: String,
  options: List(Option),
) -> Result(StringBuilder, BuilderError)

Tag with options that self-closes ie.

pub fn tag(
  document: Result(StringBuilder, BuilderError),
  label: String,
  contents: String,
) -> Result(StringBuilder, BuilderError)

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

Search Document