XML parsing library in Erlang
Clone or download
Pull request Compare This branch is 146 commits ahead, 18 commits behind paulgray:master.
Latest commit 80a4ecf Nov 6, 2018



Build Status Coverage Status

exml is an Erlang library helpful with parsing XML streams and doing some basic XML structures manipulation.


exml is a rebar3-compatible OTP application, run make or ./rebar3 compile in order to build it.

As a requirement, development headers for expat library are required.


exml can parse both XML streams as well as single XML documents at once.

To parse a whole XML document:

{ok, Parser} = exml:parse(<<"<my_xml_doc/>">>).

To generate an XML document from Erlang terms:

El = #xmlel{name = <<"foo">>,
            attrs = [{<<"attr1">>, <<"bar">>}],
            children = [{xmlcdata, <<"Some Value">>}]},

or (pastable into erl shell):

El = {xmlel, <<"foo">>,
      [{<<"attr1">>, <<"bar">>}],
      [{xmlcdata, <<"Some Value">>}]}.

Which results in:

<foo attr1='bar'>Some Value</foo>

exml:to_binary/1 works similarly.

There're also exml:to_pretty_iolist/1,3 for a quick'n'dirty document preview (pastable into erl):

El = #xmlel{name = <<"outer">>,
            attrs = [{<<"attr1">>, <<"val1">>},
                     {<<"attr2">>, <<"val-two">>}],
            children = [#xmlel{name = <<"inner-childless">>},
                        #xmlel{name = <<"inner-w-children">>,
                               children = [#xmlel{name = <<"a">>}]}]}.
io:format("~s", [exml:to_pretty_iolist(El)]).

which prints:

<outer attr2='val-two' attr1='val1'>

For an example of using the streaming API see test/exml_stream_tests.erl.