我想使用JRuby创建一些XML文件,但它不像MRI Ruby那样转义字符。
> "<node attr=#{'this is "my" complicated <String>'.encode(:xml => :attr)} />"
MRI
ruby-1.9.3-p194
=> "<node attr=\"this is "my" complicated <String>\" />"
的JRuby
jruby-1.7.2
=> "<node attr=this is \"my\" complicated <String> />"
答案 0 :(得分:1)
请不要像这样创建XML。使用Nokogiri或其他XML库。
require 'rubygems'
require 'nokogiri'
builder = Nokogiri::XML::Builder.new do |xml|
xml.node(:attr => 'this is "my" complicated <String>')
end
puts builder.to_xml
# prints: <node attr="this is "my" complicated <String>"/>
答案 1 :(得分:0)
这确实是一个JRuby错误。它现在已在master中修复,并且应该在JRuby 1.7.4中有效。