More resilient xml parsing.

This commit is contained in:
Roger Braun 2017-06-24 14:35:32 +02:00
commit 39bacba280
3 changed files with 15 additions and 5 deletions

View file

@ -1,4 +1,7 @@
defmodule Pleroma.Web.XML do
require Logger
def string_from_xpath(xpath, :error), do: nil
def string_from_xpath(xpath, doc) do
{:xmlObj, :string, res} = :xmerl_xpath.string('string(#{xpath})', doc)
@ -10,10 +13,16 @@ defmodule Pleroma.Web.XML do
end
def parse_document(text) do
{doc, _rest} = text
|> :binary.bin_to_list
|> :xmerl_scan.string
try do
{doc, _rest} = text
|> :binary.bin_to_list
|> :xmerl_scan.string
doc
doc
catch
:exit, error ->
Logger.debug("Couldn't parse xml: #{inspect(text)}")
:error
end
end
end