Home

Awesome

Exoml

A module to decode/encode xml into a tree structure.

{:exoml, "~> 0.0.4"},

Examples

Handles well formed xml/html.

Exoml.decode("<tag foo=bar>some text<self closing /></tag>")
{:root, [],
 [{"tag", [{"foo", "bar"}],
   ["some text", {"self", [{"closing", "closing"}], nil}]}]}

Handles bare strings.

Exoml.decode("what, this is not xml")
{:root, [], ["what, this is not xml"]}

Exoml.decode("")
{:root, [], []}

Handles stuff that any browser would render.

Exoml.decode("Well, it renders <b>in the browser</b>")
{:root, [], ["Well, it renders ", {"b", [], ["in the browser"]}]}

One can easily decode/1 and encode/1 without loosing too much of the original document.

xml = ~s'<tag foo="bar">some text</tag>'
^xml = Exoml.encode(Exoml.decode(xml))
# => "<tag foo=\"bar\">some text</tag>"

Performance

See bench/ directory or run mix bench upon checkout. There is one performance test that uses a 131K html file.

On a MacBookPro11,5 i7 2.5GHz 16GB RAM it yields:

benchma iterations   average time 
encode         100   12716.29 µs/op
decode          50   42088.74 µs/op

Installation

If available in Hex, the package can be installed by adding exoml to your list of dependencies in mix.exs:

{:exoml, "~> 0.0.2"}

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/exoml.