Beautiful Elixir DSL for building XML documents.
XM turns Elixir syntax into Saxy simple-form XML nodes, then delegates escaping and encoding to Saxy. It is useful for feeds, sitemaps, service integrations, and any code that needs XML without string concatenation.
Supported syntax
- local calls become XML elements:
url do ... end,loc "..." - keyword arguments become attributes:
link href: "/feed.xml", rel: "self" tag/2builds dynamic or namespaced names that are awkward as atomsfor,if,unless, andcasework inside XML blockstext/1,comment/1, andcdata/1create explicit XML node kinds- remote calls, variables, operators, and normal expressions remain Elixir
Examples
import XM
document do
urlset xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9" do
url do
loc "https://example.com/"
lastmod Date.utc_today()
end
end
end
tree do
tag "media:thumbnail", url: image_url
enddocument/2 requires exactly one root element. Use tree/1 when building
fragments to embed in a larger document.
Summary
Functions
Build a CDATA node.
Build a comment node.
Build and encode an XML document.
Build an XML element node.
Normalize nested XML nodes and scalar content.
Encode XML nodes through Saxy and return a binary.
Encode XML nodes through Saxy and return iodata.
Build a text node.
Build XML nodes without encoding them.
Types
@type prolog() :: Saxy.Prolog.t() | keyword() | nil
@type xml_node() :: Saxy.XML.element() | Saxy.XML.cdata() | Saxy.XML.comment() | Saxy.XML.characters() | Saxy.XML.ref() | Saxy.XML.processing_instruction()
Functions
@spec cdata(term()) :: Saxy.XML.cdata()
Build a CDATA node.
@spec comment(term()) :: Saxy.XML.comment()
Build a comment node.
Build and encode an XML document.
Build an XML element node.
Normalize nested XML nodes and scalar content.
Encode XML nodes through Saxy and return a binary.
Encode XML nodes through Saxy and return iodata.
@spec text(term()) :: Saxy.XML.characters()
Build a text node.
Build XML nodes without encoding them.