defmodule FeedParser.XML do @moduledoc """ A set of helpers for working with XML. To use this module, you must `require` it. """ import Record defrecord :xmlElement, extract(:xmlElement, from_lib: "xmerl/include/xmerl.hrl") defrecord :xmlAttribute, extract(:xmlAttribute, from_lib: "xmerl/include/xmerl.hrl") defrecord :xmlText, extract(:xmlText, from_lib: "xmerl/include/xmerl.hrl") @spec parse(data :: String.t()) :: {:ok, tuple()} | {:error, String.t()} def parse(data) do try do {doc, _} = data |> :binary.bin_to_list() |> :xmerl_scan.string() {:ok, doc} catch :exit, reason -> {:error, "parsing XML failed: #{inspect(reason)}"} end end end