To encode a string to XML, the xmerl_lib:export_text
function does the job, but which function does the opposite job, i.e. converts <
to >
?
I want to convert a complete string like:
<foo="bar">
To:
<foo="bar">
I never was able to find a good library for this, so I've created my own decode function.
decode(">" ++ Rest) ->
">" ++ decode(Rest);
decode("<" ++ Rest) ->
"<" ++ decode(Rest);
decode(""" ++ Rest) ->
"\"" ++ decode(Rest);
decode([]) ->
[].
According to wikipedia, there are only five character references for XML, so you should be ok with supporting these five:
& → & (ampersand, U+0026)
< → < (less-than sign, U+003C)
> → > (greater-than sign, U+003E)
" → " (quotation mark, U+0022)
' → ' (apostrophe, U+0027)