Fix XML parsing
This commit is contained in:
parent
a36dcc9535
commit
129061448a
12
lib/xml.ex
12
lib/xml.ex
|
@ -11,15 +11,15 @@ defmodule FeedParser.XML do
|
||||||
|
|
||||||
@spec parse(data :: String.t()) :: {:ok, tuple()} | {:error, String.t()}
|
@spec parse(data :: String.t()) :: {:ok, tuple()} | {:error, String.t()}
|
||||||
def parse(data) do
|
def parse(data) do
|
||||||
{doc, _} =
|
try do
|
||||||
try do
|
{doc, _} =
|
||||||
data
|
data
|
||||||
|> :binary.bin_to_list()
|
|> :binary.bin_to_list()
|
||||||
|> :xmerl_scan.string()
|
|> :xmerl_scan.string()
|
||||||
catch
|
|
||||||
:exit, reason -> {:error, "parsing XML failed: #{inspect(reason)}"}
|
|
||||||
end
|
|
||||||
|
|
||||||
doc
|
{:ok, doc}
|
||||||
|
catch
|
||||||
|
:exit, reason -> {:error, "parsing XML failed: #{inspect(reason)}"}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue