ElixirXML.Formatter (ElixirXML v0.0.1)

View Source

A simple XML formatter module that converts Elixir data structures into XML strings.

This module supports formatting:

  • Plain text (binary strings)
  • Lists of elements
  • Maps representing XML nodes with attributes and children

Summary

Functions

Formats different types of input into XML-compliant strings.

Functions

format(text)

@spec format(binary()) :: binary()
@spec format(list()) :: binary()
@spec format(%{name: binary(), attributes: list(), children: list()}) :: binary()

Formats different types of input into XML-compliant strings.

Supported Inputs:

  • binary: Returns the text as-is.
  • list: Recursively formats each element and concatenates them.
  • map: Converts a structured map into an XML tag.

Examples

iex> ElixirXML.Formatter.format("Hello")
"Hello"

iex> ElixirXML.Formatter.format(["Hello", " World"])
"Hello World"

iex> ElixirXML.Formatter.format(%{name: "br", attributes: [], children: []})
"<br />"

iex> ElixirXML.Formatter.format(%{name: "p", attributes: [], children: ["Hello"]})
"<p>Hello</p>"

format_document(elem)

@spec format_document(
  binary()
  | list()
  | %{attributes: list(), children: list(), name: binary()}
) ::
  binary()