xmerl fix

Vlad Dumitrescu vlad_dumitrescu@REDACTED
Wed Apr 10 13:18:50 CEST 2002


Hi all,

There is a thing about xmerl that I stumbled upon, in the handling of the
simple-xml format. It seems that in {Tag, Content}, Content must be an atom,
a {Tag...} tuple or a list beginning with an integer (text). But this makes
building something like "This is <em>quite</em> fun" awkward:
"This is " ++ {em, "quite"} ++ " fun"   instead of the nicer and more
natural (I think)
["This is ", {em, "quite"}, " fun"]

In case my pooint of view is accepted, I include a quick-and-dirty diff on
xmerl.erl, a very ugly hack but I couldn't come up with a nicer one without
rewriting a lot more.

best regards,
Vlad

193a194,206
> expand_content(Content = [H|_], Pos, Parents) when list(H) ->
>     case catch list_to_binary(Content) of
>       {'EXIT', _} ->
>           %% mixed content
>           {Text, Rest} = collect_text(lists:flatten(Content)),
>           [#xmlText{pos = Pos,
>                     parents = Parents,
>                     value = Text}|expand_content(Rest, Pos+1, Parents)];
>       Bin ->
>           [#xmlText{pos = Pos,
>                     parents = Parents,
>                     value = binary_to_list(Bin)}]
>     end;
203a217,218
> collect_text([H|T], Acc) when list(H) ->
>     collect_text(T, [lists:reverse(H)|Acc]);





More information about the erlang-questions mailing list