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; mv288</title>\n</hash>\n"
>> Hash.from_xml h.to_xml
=> {"hash"=>{"title"=>"hi & mv288"}}
开发者_StackOverflow中文版
If you notice line#2 and #4, the &
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 &
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.
精彩评论