An Elixir library for generating XML with a simple tuple-based structure and convenience functions.
XML Builder is an Elixir library for constructing XML documents, inspired by Jim Weirich's Ruby builder library. It provides a straightforward, tuple-based representation for XML nodes and offers convenience functions to generate XML with support for namespaces, escaping, and performance optimizations.
Elixir developers who need to generate XML documents, such as those building web services, APIs, or data export features that require XML output.
Developers choose XML Builder for its simplicity and performance, offering both low-level tuple-based construction and high-level convenience functions, along with efficient streaming via iodata support and flexible escaping strategies.
Elixir library for generating XML
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
XML nodes are represented as {name, attrs, content} tuples, making composition straightforward and aligning with Elixir's functional data structures, as shown in basic examples.
Offers multiple escaping options including default HTML escaping, CDATA sections via {:cdata, content}, and safe unescaped content with {:safe, data}, providing precise control over output safety.
The generate_iodata/2 function outputs iodata directly, avoiding binary conversion for efficient streaming, demonstrated in the sitemap example for reduced memory overhead.
Functions like element/3 and document/2 abstract manual tuple creation, improving readability and maintainability, as illustrated in the person-building examples.
Supports formatting (indented or compact), DOCTYPE declarations, and custom encoding in XML declarations, catering to various production needs.
The library is exclusively for generating XML; it cannot parse or read XML documents, necessitating additional tools like SweetXml for full XML handling.
Namespaces require explicit xmlns attributes or colon-separated names, which can be tedious and error-prone for complex namespace hierarchies compared to dedicated management.
The tuple-based syntax, while intuitive for Elixir veterans, may be less accessible for developers accustomed to DSLs or object-oriented builder patterns.
As a standalone library, it lacks built-in integrations with Elixir web frameworks like Phoenix, requiring manual setup for XML responses in web applications.