talira

XML Builder (Elixir)

Generate XML in Elixir from tuples and builder functions

open sourceMITfree

XML Builder is an Elixir library for generating XML, inspired by Jim Weirich's builder library for Ruby. Each node is a tuple of a name, an attributes map and its content or child list, built by hand or with helper functions such as document and element, and generate turns the tree into an XML string. It handles namespaces, DOCTYPE declarations, the declared encoding, standalone documents and pretty or compact formatting. Content is escaped by default, with CDATA, already-safe and raw iodata content as explicit opt-outs, and generate_iodata skips building a single binary for large documents such as sitemaps.

Problems it solves

  • generate an XML document such as a sitemap or feed from an Elixir app
  • build XML for a SOAP or partner API request in Elixir without string templates
  • make sure the XML my Elixir code writes is properly escaped

Features

  • XML nodes as {name, attributes, content} tuples or document/element helper calls
  • Escapes content by default, with CDATA, safe and raw iodata opt-outs
  • Namespaces, DOCTYPE declarations, encoding and standalone declarations
  • Pretty-printed or compact output
  • generate_iodata for large documents without one big binary

Alternatives

The same job

These do what XML Builder (Elixir) does.

  1. SweetXml Query XML in Elixir with XPath sigils
  2. Saxy Fast streaming XML SAX parser and encoder for Elixir
  3. Erlsom XML parser for Erlang: SAX parsing and XML Schema based data binding

Compare XML Builder (Elixir) with the top 3