Preventing LibXML from encoding all special characters to their html form?

30 views
Skip to first unread message

Michel Pigassou

unread,
Aug 21, 2011, 11:36:21 AM8/21/11
to rubyonra...@googlegroups.com
Hi.

From what I unsertand, Rails uses by default LibXML.
When doing a to_xml, it encodes all special characters, which is useful for <, &, >, etc. but not really for ü, ô, etc.
First, I can't convert them back from &#x252; to "û" which is very frustrating for my tests.
And I cannot manage to force LibXML not to encode all characters.

Any help? Thanks.

Michel Pigassou

unread,
Aug 21, 2011, 1:14:04 PM8/21/11
to rubyonra...@googlegroups.com
For those who wonder, the same encoding can be applied this way:

require 'builder/xchar'
string.to_xs

And to decode, you can do encoded_string.gsub(/\&#([a-f0-9]*);/) { |s| [$1.to_i].pack('U*') }

Thank you Builder doc!
Reply all
Reply to author
Forward
0 new messages