A thin Elixir wrapper around :xmerl for simple and effective XML querying and conversion to Elixir data structures.
SweetXml is an Elixir library that provides a simple and expressive way to query and parse XML documents. It wraps the Erlang :xmerl module, allowing developers to convert XML data into native Elixir structures like maps, lists, strings, and numbers using XPath-like syntax. It solves the problem of cumbersome XML handling in Elixir by offering a clean API with streaming support and transformation capabilities.
Elixir developers who need to parse, query, or transform XML data from APIs, feeds, or legacy systems. It's particularly useful for backend developers working with XML-based web services or data integration pipelines.
Developers choose SweetXml for its elegant API that reduces boilerplate compared to raw :xmerl usage, its support for streaming large documents, and its ability to directly map XML to Elixir data structures with minimal code. The library's focus on safety and composability makes it a reliable choice for production XML processing.
SweetXml is an Elixir library that simplifies working with XML by providing a clean, expressive API for querying and converting XML documents into native Elixir data structures like maps, lists, strings, and numbers. It wraps the Erlang :xmerl module, making XML parsing more accessible and intuitive for Elixir developers.
~x sigil to write concise XPath 1.0 queries with modifiers for lists, strings, integers, and optional nodes.transform_by/2 for data cleanup or formatting.SweetXml aims to make XML parsing in Elixir as straightforward as possible, providing a thin, idiomatic layer over :xmerl that emphasizes simplicity, composability, and safety.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
The ~x sigil allows writing XPath 1.0 queries with modifiers for lists, strings, integers, and more, making code readable and expressive, as shown in the README examples for extracting matchup names.
Supports direct transformation of XML hierarchies into nested Elixir maps and keyword lists in a single query, demonstrated with complex matchup and team data extraction.
Provides stream_tags/2 for parsing large XML documents with memory management options, allowing incremental processing without loading entire files, as detailed in the streaming section.
Allows custom transformation functions via transform_by/2 for data cleanup, such as capitalizing strings or converting types, enhancing processing flexibility in nested queries.
Offers separate parsing with security options like disabling DTD processing via parse/2, as recommended in the README for safe handling of external documents.
Explicitly warns that only XPath 1.0 is supported due to wrapping :xmerl, restricting the use of newer XPath features available in other libraries.
Relies on Erlang's :xmerl module, which may require manual installation of erlang-xmerl on some Linux systems, adding setup complexity and potential compatibility issues.
Requires careful configuration with namespace_conformant: true parsing and add_namespace/2 calls, which can be error-prone and less intuitive for documents with multiple namespaces.
The streaming feature has a warning about potential memory leaks if the discard option is not used, necessitating additional code and caution for large documents.