Xmlixer

A simple wrapper around erlang’s xmerl to generate XML in elixir.

Installation

The package can be installed as:

  1. Add xmlixer to your list of dependencies in mix.exs:
```elixir
def deps do
  [{:xmlixer, "~> 0.1.0"}]
end
```
  1. Ensure xmlixer is started before your application:
```elixir
def application do
  [applications: [:xmlixer]]
end
```

XML node is a tuple

{Tag, %{Attribute}, [content]}

Tag can be a string or an atom.
Attributes are Elixir Maps.
Content can be a string, tuple (XML node) or a List tuples.

Usage

Example

iex> import Xmlixer

#main xml
iex> fruits = create_node("fruits")
{:fruits, [], []}

#inner node
iex> apple = create_node("apple") |> add_attributes(
              %{color: "red", seeded: :true}
            ) |> add_content("give it to the doctor.")
{:apple, [color: "red", seeded: true], [["give it to the doctor."]]}

iex> fruits |> add_content(apple) |> serialize 
&#39;<?xml version="1.0"?><fruits><apple color="red" seeded="true">give it to the doctor.</apple></fruits>&#39;

#adding xml declaration
iex> prolog = ~s(<?xml version="1.0" encoding="UTF-8"?>)
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"

iex> fruits |> add_content(apple) |> serialize(prolog)
&#39;<?xml version="1.0" encoding="UTF-8"?><fruits><apple color="red" seeded="true">give it to the doctor.</apple></fruits>&#39;