xmap

XML to Map converter.


License
MIT

Documentation

XMap

Build Status

XML to Map converter.

XMap transforms an XML string into a Map containing a collection of pairs where the key is the node name and the value is its content.

Examples

Here is an example:

iex> xml = """
...> <?xml version="1.0" encoding="UTF-8"?>
...> <blog>
...>   <post>
...>     <title>Hello Elixir!</title>
...>   </post>
...>   <post>
...>     <title>Hello World!</title>
...>   </post>
...> </blog>
...> """
iex> XMap.from_xml(xml)
%{"blog" => %{"post" => [%{"title" => "Hello Elixir!"},
                         %{"title" => "Hello World!"}]}}
iex> XMap.from_xml(xml, keys: :atoms)
%{blog: %{post: [%{title: "Hello Elixir!"}, %{title: "Hello World!"}]}}

Keys can be converted to atoms with the keys: :atoms option. Unless you absolutely know what you're doing, do not use the keys: :atoms option. Atoms are not garbage-collected, see Erlang Efficiency Guide for more info:

Atoms are not garbage-collected. Once an atom is created, it will never be removed. The emulator will terminate if the limit for the number of atoms (1048576 by default) is reached.

Installation

Add XMap to your project's dependencies in mix.exs:

def deps do
  [{:xmap, "~> 0.2"}]
end

And fetch your project's dependencies:

$ mix deps.get

Documentation

Documentation is available at https://hexdocs.pm/xmap

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/fertapric/xmap. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

Running tests

Clone the repo and fetch its dependencies:

$ git clone git@github.com:fertapric/xmap.git
$ cd xmap
$ mix deps.get
$ mix test

Building docs

$ mix docs

Copyright and License

Copyright 2017 Fernando Tapia Rico

XMap source code is licensed under the MIT License.