[erlang-questions] How to best parse XML in erlang?

Rapsey <>
Sun Jul 28 06:45:29 CEST 2013


This is what I use. It turnes the XML into:
[{ElementName,Properties,SubitemsOrValue},..]


parsexml(InputXml,Opt) ->
	F = fun(B) ->
			{Xml,_} = xmerl_scan:string(B,
[{space,normalize},{encoding,"utf-8"},{validation,off}|Opt]),
			strip_whitespace(xmerl_lib:simplify_element(Xml))
		end,	
	try F(InputXml) of
		Res ->
			Res
	catch
		error:_X ->
			false
	end.

strip_whitespace({El,Attr,Children}) ->
  NChild = lists:filter(fun(X) ->
    case X of
    " " -> false;
    _   -> true
    end
  end,Children),
  Ch = lists:map(fun(X) -> strip_whitespace(X) end,NChild),
  {El,Attr,Ch};
strip_whitespace(String) ->
	String.


On Sun, Jul 28, 2013 at 6:16 AM, Yves S. Garret
<> wrote:
> Hello.  I've recently found out about erlsom and xmerl on erlang.  What
> would you recommend for a
> way to parse XML files in erlang?
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list