实际上,我在使用 Rails 3.2.1 的 jruby-1.6.7 中使用 REXML::Document 解析 XML 字符串时遇到了问题。
我有一个字符串
<?xml version="1.0" encoding="US-ASCII"?><a><b>Something</b></a>
它曾经与 jruby-1.6.5.1 一起工作
doc = REXML::Document.new(xml_string)
截至目前,它失败了:
failed - can't convert NilClass into String
backtrace of deliver! org/jruby/RubyIconv.java:207:in `initialize'
org/jruby/RubyIconv.java:391:in `conv'
/opt/jruby/lib/ruby/1.8/rexml/encodings/ICONV.rb:12:in `encode'
/opt/jruby/lib/ruby/1.8/rexml/source.rb:55:in `encoding='
/opt/jruby/lib/ruby/1.8/rexml/source.rb:45:in `initialize'
/opt/jruby/lib/ruby/1.8/rexml/source.rb:11:in `create_from'
/opt/jruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:121:in `stream='
/opt/jruby/lib/ruby/1.8/rexml/parsers/baseparser.rb:110:in `initialize'
/opt/jruby/lib/ruby/1.8/rexml/parsers/treeparser.rb:9:in `initialize'
/opt/jruby/lib/ruby/1.8/rexml/document.rb:227:in `build'
/opt/jruby/lib/ruby/1.8/rexml/document.rb:43:in `initialize'
将标题更改为如下所示:
<?xml version="1.0" encoding="utf-8"?><a><b>Something</b></a>
一切安好。我是否错过了系统上的库,这是一个已知问题吗?US-ASCII 无效吗?