实际上我遇到了使用Rails 3.2.1在jruby-1.6.7中使用REXML :: Document解析XML String的问题。
我有一个像
这样的字符串<?xml version="1.0" encoding="US-ASCII"?><a><b>Something</b></a>
在执行
时曾经使用jruby-1.6.5.1doc = 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>
一切都很好。我错过了系统上的lib,这是一个已知的问题吗? US-ASCII无效吗?
答案 0 :(得分:0)
FWIW - 不是答案,但我也从JRuby 1.6.5 / Rails 3.1.3转到1.6.7 / Rails 3.2.3并且我使用SimpleXML尝试解析此xml时出现相同的“新”错误: / p>
<?xml version="1.0" encoding="ISO-8859-1"?>
<simulacao><ApoliceAuto Sistema="GISU" Utilizador="USER"
ReferenciaExterna="16" Ramo="90"
TipoSeguro="10"><Packs><Pack
codPack="1"><ValorAnualPack>240.89</ValorAnualPack><
ValorSemestralPack>124.39</ValorSemestralPack><
ValorContinuadoSemestralPack>
118.84</ValorContinuadoSemestralPack><ValorTrimestralPack>66.12<
/ValorTrimestralPack><ValorContinuadoTrimestralPack>60.57<
/ValorContinuadoTrimestralPack><ValorMensalPack>27.28</ValorMensalPack><
ValorContinuadoMensalPack>21.73</ValorContinuadoMensalPack><Mensagens/><
/Pack></Packs></ApoliceAuto></simulacao>
看起来像这样(通过SO解析器:))
&lt;?xml version =“1.0”encoding =“ISO-8859-1”?&gt; &lt; simulacao&gt;&lt; ApoliceAuto Sistema =“GISU”Utilizador =“USER”ReferenciaExterna =“16”Ramo =“90”TipoSeguro =“10”&gt;&lt; Packs&gt;&lt; Pack codPack =“1”&gt;&lt; ValorAnualPack&GT; 240.89&LT; / ValorAnualPack&GT;&LT; ValorSemestralPack&GT; 124.39&LT; / ValorSemestralPack&GT;&LT; ValorContinuadoSemestralPack&GT; 118.84&LT; / ValorContinuadoSemestralPack&GT;&LT; ValorTrimestralPack&GT; 66.12&LT; / ValorTrimestralPack&GT;&LT; ValorContinuadoTrimestralPack&GT; 60.57&LT; / ValorContinuadoTrimestralPack&GT;&LT; ValorMensalPack&GT; 27.28&LT; / ValorMensalPack&GT;&LT; ValorContinuadoMensalPack&GT; 21.73&LT; / ValorContinuadoMensalPack&GT;&LT; Mensagens /&GT;&LT; /包装&GT;&LT; /包&GT;&LT; / ApoliceAuto&GT;&LT; / simulacao&GT;