[erlang-questions] Rant: I hate parsing XML with Erlang
Ulf Wiger (TN/EAB)
ulf.wiger@REDACTED
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:
17>xmerl_scan:file(".../xmerl-0.18.1/priv/testdata/test3.xml",
[{hook_fun,
fun(#xmlElement{name = N,
attributes = As,
content = C},S) ->
As1 = [{K,V} ||
#xmlAttribute{name=K,
value=V} <- As],
{{N,As1,C},S};
(#xmlText{value = V}, S) ->
{V,S}; (X,S) -> {X, S} end}]).
{{'People',[],
["\n ",
{comment,[],["This is a comment"]},
"\n ",
{'Person',[{'Type',"Personal"}],["\n "]},
"\n"]},
[]}
BR,
Ulf W
More information about the erlang-questions
mailing list