exoml v0.0.10 Exoml
A module to decode/encode xml into a tree structure.
The aim of this parser is to be able to represent any xml document as a tree-like structure, but be able to put it back together in a sane way.
In comparison to other xml parsers, this one preserves broken stuff. The goal is to be able to decode the typical broken html document, modify it, and encode it again, without loosing too much of its original content.
Currently the parser preserves whitespace between <xml> nodes, so <pre> or <textarea> tags should be unaffected,
by a decode/1
into encode/1
.
The only part where the parser tidies up, is the attr="part"
of a <xml attr="part"> node.
With well-formed XML, the parser does work really well.
Link to this section Summary
Functions
Returns a tree representation from the given xml string.
Returns a string representation from the given xml tree
Link to this section Types
Link to this section Functions
Returns a tree representation from the given xml string.
Examples
iex> Exoml.decode("<tag foo=bar>some text<self closing /></tag>")
{:root, [],
[{"tag", [{"foo", "bar"}],
["some text", {"self", [{"closing", "closing"}], nil}]}]}
iex> Exoml.decode("what, this is not xml")
{:root, [], ["what, this is not xml"]}
iex> Exoml.decode("Well, it renders <b>in the browser</b>")
{:root, [], ["Well, it renders ", {"b", [], ["in the browser"]}]}
iex> Exoml.decode("")
{:root, [], []}
Returns a string representation from the given xml tree
Note when encoding a previously decoded xml document: Exoml does not perfectly preserve everything from a decoded xml document. In general, it preserves just well enough, but don't expect a 1-1 conversion.
Examples
iex> xml = ~s'<tag foo="bar">some text</tag>'
iex> ^xml = Exoml.encode(Exoml.decode(xml))
"<tag foo="bar">some text</tag>"