Merge branch 'feld-Logger' into 'develop'
[akkoma] / lib / pleroma / web / xml / xml.ex
1 defmodule Pleroma.Web.XML do
2 require Logger
3
4 def string_from_xpath(_, :error), do: nil
5 def string_from_xpath(xpath, doc) do
6 {:xmlObj, :string, res} = :xmerl_xpath.string('string(#{xpath})', doc)
7
8 res = res
9 |> to_string
10 |> String.trim
11
12 if res == "", do: nil, else: res
13 end
14
15 def parse_document(text) do
16 try do
17 {doc, _rest} = text
18 |> :binary.bin_to_list
19 |> :xmerl_scan.string
20
21 doc
22 catch
23 :exit, _error ->
24 Logger.debug("Couldn't parse XML: #{inspect(text)}")
25 :error
26 end
27 end
28 end