Why? Browser can translate &#xxxx; into Chinese, but I want to get the real UTF-8 Chinese characters. Please kindly help, thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
It''s built into Builder::XmlMarkup. You can run a transform on the returned XML to un-escape characters that are encoded into numbers. This assumes that all characters from emitted from #to_xml were Unicode. def unescape_numeric_entities(xml) xml.gsub(/&#(\d+);/) do |c| [$1.to_i].pack("U") rescue c end end unescape_numeric_entities(record.to_xml) On May 14, 1:25 pm, Datou <2sim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Why? > > Browser can translate &#xxxx; into Chinese, but I want to get the real > UTF-8 Chinese characters. > > Please kindly help, thanks!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you very much! On May 15, 11:24 am, eden li <eden...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It''s built into Builder::XmlMarkup. You can run a transform on the > returned XML to un-escape characters that are encoded into numbers. > This assumes that all characters from emitted from #to_xml were > Unicode. > > def unescape_numeric_entities(xml) > xml.gsub(/&#(\d+);/) do |c| > [$1.to_i].pack("U") rescue c > end > end > > unescape_numeric_entities(record.to_xml) > > On May 14, 1:25 pm, Datou <2sim...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Why? > > > Browser can translate &#xxxx; into Chinese, but I want to get the real > > UTF-8 Chinese characters. > > > Please kindly help, thanks!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---