xmerl(3)
β¨ xmerl β the Erlang Module Definition, bestie edition β¨
okay so real talk: this is xmerl(3), the Erlang module definition for xmerl. That's the manual name, that's the vibe, and yes we are absolutely getting into it. π
πΈ NAME πΈ
xmerl β Functions for exporting XML data to an external format. That's it, that's the whole job description, and she does it beautifully. π
π¦ DESCRIPTION π¦
(ngl bestie, the original leaves this one kind of empty, so we're just gonna wave at it and move on to the good stuff) β¨
π DATA TYPES π
callback()::module() | [module()].
A callback module, or a whole list of inherited callback modules. Yeah, she can have ancestors. It's giving family tree energy. π³
element()::xmlText() | xmlElement() | xmlPI() | xmlComment() | xmlDecl().
A normal, well-formed, no-notes XML content element. The whole squad. π
simple_attribute()::
xmlAttribute() |
{fun((_) -> _), term()} |
{Key :: atom(), Value :: term()}.
The "simple-form" XML attribute. chill mode activated π§
simple_element()::
{Tag :: atom(),
Attributes ::
[{Name :: atom(), Value :: iolist() | atom() |
integer()}],
Content :: [simple_element()]} |
{Tag :: atom(), Content :: [simple_element()]} |
(Tag :: atom() | (IOString :: iolist() | element())).
The "simple-form" XML content element. Literally the low-effort-but-still-iconic version. π
xmlAttribute()::#xmlAttribute{}.
That's record #xmlAttribute{}, periodt.
xmlComment()::#xmlComment{}.
Record #xmlComment{}. π«Ά
xmlDecl()::#xmlDecl{}.
Record #xmlDecl{}. β¨
xmlDocument()::#xmlDocument{}.
Record #xmlDocument{}. π
xmlElement()::#xmlElement{}.
Record #xmlElement{}. π₯
xmlNamespace()::#xmlNamespace{}.
Record #xmlNamespace{}. π
xmlNsNode()::#xmlNsNode{}.
Record #xmlNsNode{}. π
xmlPI()::#xmlPI{}.
Record #xmlPI{}. π
xmlText()::#xmlText{}.
Record #xmlText{}. π
π₯ FUNCTIONS π₯
callbacks(Module :: module()) -> [module()].
Find the list of inherited callback modules for a given module. Basically "who's in your bloodline, bestie?" π³
export(Content, Callback, RootAttributes) -> ExportedFormat :: term()
with
Content :: [Element],
Element :: element(),
Callback :: callback(),
RootAttributes :: [simple_attribute()].
Export XML content. π
Exports normal, well-formed XML content, using the callback module you specified.
Element is any of:
#xmlText{}#xmlElement{}#xmlPI{}#xmlComment{}#xmlDecl{}
(Go look in xmerl.hrl for the record definitions, bestie, they're all in there.) Text inside #xmlText{} elements can be deep lists of characters and/or binaries. yes, deep, she contains multitudes. π
RootAttributes is a list of #xmlAttribute{} attributes for the #root# element, which implicitly becomes the parent of the Content you handed over. So the tag-handler function for #root# gets called with the complete exported data of Content. Root attributes are the move when you wanna specify encoding or other metadata of an XML or HTML document. π
The Callback module should contain hook functions for all tags present in the data structure. Every hook function must have this exact format:
Tag(Data, Attributes, Parents, E)
where E is the corresponding #xmlElement{}, Data is the already-exported contents of E, and Attributes is the list of #xmlAttribute{} records of E. And finally, Parents is the list of parent nodes of E, on the form [{ParentTag::atom(), ParentPosition::integer()}].
not me stressing about format β yes, that exact shape, don't freestyle it π
The hook function should return either the data to be exported, or a tuple {'#xml-alias#', NewTag::atom()}, or a tuple {'#xml-redefine#', Content}, where Content is a content list (which can be on simple-form; see export_simple/2 for details).
A callback module can inherit definitions from other callback modules, through the required function '#xml-interitance#'() -> [ModuleName::atom()]. (yes, that's how it's spelled in the original, we don't touch it, we don't fix it, we respect it π«‘)
See also: export/2, export_simple/3.
export_content(Content, Callbacks) -> _
with
Content :: [element()],
Callbacks :: [module()].
Export normal XML content directly, without further context. straight to the point, no small talk. β¨
export_element(Element, Callback) -> _
with
Element :: element(), Callback :: callback().
Exports a normal XML element directly, without further context. just the one element, main character energy π
export_element(Element, Callback, CallbackState) -> ExportedFormat
with
Element :: element(),
Callback :: callback(),
CallbackState :: term(),
ExportedFormat :: term().
For on-the-fly exporting during parsing (SAX style) of the XML document. live, unhinged, in real time π₯
export_simple(Content, Callback, RootAttributes) -> ExportedFormat :: term()
with
Content :: [Element],
Element :: simple_element(),
Callback :: callback(),
RootAttributes :: [simple_attribute()].
Export "simple-form" XML content. π¦
Exports "simple-form" XML content, using the callback module you specified.
Element is any of:
{Tag, Attributes, Content}{Tag, Content}TagIOString#xmlText{}#xmlElement{}#xmlPI{}#xmlComment{}#xmlDecl{}
where
Tag = atom()Attributes = [{Name, Value}]Name = atom()Value = IOString | atom() | integer()
Normal-form XML elements can thus be included in the simple-form representation. Note that content lists must be flat β no nesting shenanigans, bestie, we're keeping it one level. An IOString is a (possibly deep) list of characters and/or binaries.
RootAttributes is a list of:
XmlAttributes = #xmlAttribute{}
See export/3 for details on the callback module and the root attributes. The XML-data is always converted to normal form before being passed to the callback module. always. no exceptions. π
See also: export/3, export_simple/2.
export_simple_content(Content, Callback) -> _
with
Content :: [simple_element()],
Callback :: callback().
Exports simple XML content directly, without further context. π
export_simple_element(Element, Callback) -> _
with
Element :: simple_element(),
Callback :: callback().
Export a simple XML element directly, without further context. one element, zero drama, we love to see it πΈ
π that's the whole page, bestie, you read all of it, I'm so proud π«Ά
sign-off time: this lil beaut was brought to you by Ericsson AB, running xmerl 2.2, and yeah, it's the xmerl(3) page β slay, ate, no crumbs left. π
β¨
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms