[erlang-questions] Rant: I hate parsing XML with Erlang

Ulf Wiger (TN/EAB) <>
Tue Oct 23 16:09:58 CEST 2007

Joel Reymont wrote:
> I only have so much horizontal real-estate on my screen and I totally  
> hate how xmlElement and xmlAttribute take so much of it. I also hate  
> how XML parsing code looks in Erlang.

The original idea with xmerl (dating back to 2001), was
to map XML to S-expressions. The records came about when
trying to support namespaces, XPATH, et al.

There may be some gotchas in what assumptions xmerl_scan
makes about the hook functions, but at least for simple
XML, you can call xmerl_scan with your own hook function:

       fun(#xmlElement{name = N,
                       attributes = As,
                       content = C},S) ->
              As1 = [{K,V} ||
                                   value=V} <- As],
          (#xmlText{value = V}, S) ->
              {V,S}; (X,S) -> {X, S} end}]). 
            ["\n  ",
             {comment,[],["This is a comment"]},
             "\n  ",
             {'Person',[{'Type',"Personal"}],["\n  "]},

Ulf W

More information about the erlang-questions mailing list