Proximal.Document behaviour (proximal v0.2.3)
When you need to implement a parser for a structure, you could add the following code:
defmodule MyStruct do
use Proximal.Document
alias Proximal.Xmlel
defstruct [:name, :surname]
@impl Proximal.Document
def render(%__MODULE__{name: name, surname: surname}) do
Xmlel.new("mystruct", %{}, [
Xmlel.new("name", %{}, [name]),
Xmlel.new("surname", %{}, [surname])
])
end
end
The code should let you to create your data in the way you need and
thanks to the implementation of the render/1
function, you could use:
%MyStruct{name: "Manuel", surname: "Rubio"}
|> Proximal.to_xmlel()
To get the representation in %Xmlel{}
structs and even adding at the
end of that pipe to_string/1
to get the XML in a string.
Summary
Callbacks
@callback render(struct()) :: Proximal.Xmlel.t()