ElixirXML.Formatter (ElixirXML v0.0.1)
View SourceA 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
@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>"