XmlParser
This parser transforms XML
to a format that can be consumed by
XmlBuilder.
Currently this parser is just a wrapper around Quinn parser.
It can be rewritten to gain more performance.
Installation
The package can be installed as:
-
Add
xml_parser
to your list of dependencies inmix.exs
:def deps do [{:xml_parser, "~> 0.1.0"}] end
-
Ensure
xml_parser
is started before your application:def application do [applications: [:xml_parser]] end
Usage
xml = "<person id=\"12345\"><first>Josh</first><last>Nussbaum</last></person>"
data = XmlParser.parse xml
# {:person, %{id: 12345}, [{:first, nil, "Josh"}, {:last, nil, "Nussbaum"}]}
# and don't forget to include xml_builder into deps before using it
XmlBuilder.build data
# <person id="12345"><first>Josh</first><last>Nussbaum</last></person>
Documentation is also available.
Gotchas
Quinn
can't parse XML with siblings on the top level of a document, so XML document must
have only one root element.
<good>
<data>Data!</data>
<data>More data!</data>
</good>
<bad>Data!</bad>
<bad>Lost data</bad>