Created
April 28, 2017 21:34
-
-
Save JLarky/d10ffdce805d39878929cf4c46183bee to your computer and use it in GitHub Desktop.
Encode html entities or escape html with Elixir and xmerl Erlang module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp html_encode(text) do | |
[_ | xml] = :xmerl.export_simple([{:xmlText, [], 0, [], text, :text}], :xmerl_xml) | |
:erlang.iolist_to_binary(xml) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't
xmerl_lib:export_text/1
be better?https://stackoverflow.com/questions/3339014/how-do-i-xml-encode-a-string-in-erlang