I’m don’t know how expansive the choice needs to be, really—parsing and building are pretty straightforward until you need SAX, and even then you just use a SAX parser if you’re memory constrained. I’ve built a few XML-handling things in Elixir just fine with sweet_xml and xml_builder. Usually end up with something like this as my main entrypoint, with application-specific helpers for common workflows, and submodules for specific domains (ex XML.SOAP).
XML module
defmodule XML do
defmacro __using__(_options \\ []) do
quote do
import XML, only: [sigil_x: 1, sigil_x: 2]
end
end
@type document() :: SweetXml.doc()
@type element() :: SweetXml.xmlElement()
####
# XML builder functions
##
defdelegate document(elements), to: XmlBuilder
defdelegate document(name, attrs_or_content), to: XmlBuilder
defdelegate document(name, attrs, content), to: XmlBuilder
defdelegate element(name), to: XmlBuilder
defdelegate element(name, attrs), to: XmlBuilder
defdelegate element(name, attrs, content), to: XmlBuilder
####
# XML parser functions
##
defdelegate generate(any, options \\ []), to: XmlBuilder
defdelegate parse(document, options \\ []), to: SweetXml
defdelegate sigil_x(path, modifiers \\ []), to: SweetXml
defdelegate xpath(parent, spec, subspec \\ []), to: SweetXml
end
That really depends on what you’re doing with the XML. If you’re looking for feedback, share some details about the problem you’re trying to solve with us!


















