How to check if XML is well-formed in Elixir -


I am receiving the situation in which I need to ignore the XML file which can not be created properly .

I'm using SweetXml which uses xmerl

I have a badly formed XML which is not a location between two attributes

is_well_formed have work. - With a simple Boolean reaction it would be a lot better.

Xmerl tries to parse the file, does not like it, and therefore sends an exit.

I have not yet learned about observers, but it seems to me like a case for them.

Is there an easy way to deal with the signal at the beginning or the exit?

  defmodule XmlIsWellFormed.WellFormed Def is_well_formed (Xml) Import SweetXml xml_string = to_string xml result = xml_string | & Gt; Pars # Pars exits # FYI - SweetXml.parse: #def parsing (doc) # {parsed_doc, _} =: xmerl_scan.string (doc) # parsed_doc # end # Note: Inspection results are not of any use xmerl Sends an exit with: # "whitespace_required_between_attributes" # Something like this will happen: # try do # result =: xmerl_scan.string (xml) # rescue #: exit, _ - & gt; Zero # end end end rubbish_xml = '& lt; Rubbishml & gt; & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" dir = "ltr" lang = "en-US" xmlns: og = "http: //ogp.me/ns#" xmlns: fb = "Http://www.facebook.com/2008/fbml" & gt; & Lt; / Rubbishml & gt; 'XmlIsWellFormed.WellFormed.is_well_formed rubbish_xml  

You try / rescue , Which only hides exceptions to the other side, it can be stopped with:

  def is_well_formed (xml) do try do xml | & Gt; To_string | & Gt; Parse the right grip: exit, _ - & gt; IEX will print the message as a message in the console, but the program will continue to execute:  
  iex> XmlIsWellFormed.WellFormed.is_well_formed ~ s (& lt; a b = "" c = "" />) 3437- Fatal: {whitespace_required_between_attributes} incorrect iex & gt; Although,  hold  ing and  Rescue  IEL exception is very unusual in nectar. You should design your application with a supervised tree so that it can know how to breathe properly. Then you simply, and the supervisor will take care of the rest. 


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -