xmb

Extensible Markup Builder

A tiny XML builder for Gleam.

let html = 
  x("greeting", [], [text("Hello, Joe!")])
  |> render
  |> string_tree.to_string
assert html == "<greeting>Hello, Joe!</greeting>"

This package doesn’t do much. If you’d like more features, check out these alternatives:

Types

pub type Xml

Functions

pub fn cdata(content: String) -> Xml

Create a XML text node as CDATA rather than escaping XML entities. This is often easier to read and will render slightly faster.

pub fn dangerous_unescaped_fragment(s: StringTree) -> Xml

Dangerously inject some string content into the XML document. This will not be escaped! Your string must be valid XML syntax! Do not mess up!

pub fn escape(content: String) -> String
pub fn fragment(s: List(Xml)) -> Xml

Create XML from multiple existing nodes.

pub fn nothing() -> Xml

Create a text node of nothing at all!

pub fn render(xml: List(Xml)) -> StringTree

Render an XML document.

pub fn render_fragment(element: Xml) -> StringTree

Render XML to a fragment, that is a XML document without an XML declaration.

pub fn text(content: String) -> Xml

Create a XML text node.

pub fn x(
  tag: String,
  attributes: List(#(String, String)),
  children: List(Xml),
) -> Xml

Create a XML element with attributes and children.

Search Document