Created: 2011-07-07 10:10
Updated: 2016-12-20 13:37

Inline XML Parse Transform Utility

An inline_xml parse transform, based loosely on this.


Simply include the relevant header file and you're good to go:


demo() ->
    Xml = '<foo><bar name="123" /></foo>',
        [],_,undeclared} = Xml.
    io:format("~p~n", [Xml]).

The parse transform will currently handle (i.e., inline) XML (atoms) in each of the following situations:

  1. In an assignment (i.e., match) operation such as X = ''
  2. In a match clause of a case expression

Example use cases are provided in the examples subdirectory.

Alternative XML Libraries

By default, inline_xml uses the standard erlxml library to convert your atom into an AST during the parse_transform. You can tell inline_xml to use another library instead, by defining the alternative API as an M/F/A triple in your module like so:

-xml_api({erlsom, simple_form, []}).

demo() ->
    Xml = '<foo attr="baz"><bar>x</bar><bar>y</bar></foo>',
         [{"bar",[],["x"]},{"bar",[],["y"]}]} = Xml,
    io:format("~p~n", [Xml]).

Looking into the inline_xml_erlsom module and the inline_erlsom.hrl header in the inline_erlsom extension should give some useful insights into how API customisations and plugins work.

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more