How do I stop logging exits?

I am using sweet_xml. It raises :exit for every imaginable problem, instead of just returning {:error, _}

I am making my own function, but the problem is it still logs red text to the console:

15:42:17.001 [error] 3907- fatal: :expected_element_start_tag

Is it possible to stop that?

  defp xmap_safe(xml, fields) do
    try do
      {:ok, xmap(xml, fields)}
    catch
      :exit, _ -> {:error, %{}}
    end
  end

side question, why does fn -> (x, y) not work but fn -> {x, y} does? I can’t seem to find this referenced anywhere

Those logs are coming from xmerl which is the underlying library sweet_xml uses. They can only be disabled by passing {:quiet, true} option to :xmerl_scan.string that SweetXml calls. Unfortunately, there doesn’t seem to be a way to pass that option when calling SweetXml.xpath or SweetXml.xmap.

2 Likes

Damn… well ok :expressionless:

Are there any other XML parsers that use xpath?

Context? It kind of looks like a anonymous function definition - but it’s not finished.

  • {x,y} looks looks a tuple
  • No idea what (x,y) is supposed to be.
1 Like

Oh, well other than end its not missing anything.

fn -> {x, y} IO.puts(x) end

I’m passing in a map… but it doesnt work when using (). I always thought they were totally interchangeable but it appears theyre not

Try this:

%{a: 1} |> Enum.each(fn (x, y) -> IO.puts(x) end)
%{a: 1} |> Enum.each(fn {x, y} -> IO.puts(x) end)
%{a: 1} |> Enum.each(fn ({key,_value}) -> IO.puts(key) end)
2 Likes

Ahh :man_facepalming:t2:

Simple xmerl usage demo in Elixir

https://groups.google.com/forum/#!topic/elixir-lang-talk/PVJzCMelQgQ

http://erlang.org/doc/man/xmerl_scan.html

3 Likes

oh nice, thanks!

1 Like

I use Meeseeks personally, if you can load it all into memory then it uses a Rust backend to do it all crazy-fast. If you need a streaming interface to not load it all then something else.

1 Like