1 defmodule Pleroma.XmlBuilder do
2 def to_xml({tag, attributes, content}) do
3 open_tag = make_open_tag(tag, attributes)
5 content_xml = to_xml(content)
7 "<#{open_tag}>#{content_xml}</#{tag}>"
10 def to_xml({tag, %{} = attributes}) do
11 open_tag = make_open_tag(tag, attributes)
16 def to_xml({tag, content}), do: to_xml({tag, %{}, content})
18 def to_xml(content) when is_binary(content) do
22 def to_xml(content) when is_list(content) do
23 for element <- content do
29 def to_xml(%NaiveDateTime{} = time) do
30 NaiveDateTime.to_iso8601(time)
33 def to_doc(content), do: ~s(<?xml version="1.0" encoding="UTF-8"?>) <> to_xml(content)
35 defp make_open_tag(tag, attributes) do
37 for {attribute, value} <- attributes do
38 "#{attribute}=\"#{value}\""
42 [tag, attributes_string] |> Enum.join(" ") |> String.trim()