开发者

Hash.from_xml double escapes &

>> h={:title => "hi & mv288" }
=> {:title=>"hi & mv288"}
>> h.to_xml
=> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<hash>\n  <title>hi &amp;amp; mv288</title>\n</hash>\n"
>> Hash.from_xml h.to_xml
=> {"hash"=>{"title"=>"hi & mv288"}}
开发者_StackOverflow中文版

If you notice line#2 and #4, the &amp; characters in the title value became & after a series of Hash.to_xml and from_xml method calls.

Is there any way to prevent Hash.from_xml from converting &amp; into &.


We switched the xml parser to Nokogiri to resolve this issue.

Add this line in your environment.rb

ActiveSupport::XmlMini.backend = 'Nokogiri'

You will have to have nokogiri gem installed though. If you need a pure java implementation of nokogiri, check this out. https://github.com/tenderlove/nokogiri/wiki/pure-java-nokogiri-for-jruby

The installation command is,

gem install nokogiri --pre

You may also use LibXml as XmlMiini.backend to resolve this issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜