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_parserto your list of dependencies inmix.exs:
```elixir
def deps do
[{:xml_parser, "~> 0.1.0"}]
end
```-
Ensure
xml_parseris started before your application:
```elixir
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>