简体   繁体   中英

REXML::Document.new fails parsing with US-ASCII encoded XML

actually I've encountered a problem about parsing a XML String with REXML::Document in jruby-1.6.7 with Rails 3.2.1.

I have a string like

<?xml version="1.0" encoding="US-ASCII"?><a><b>Something</b></a>

It used to work with jruby-1.6.5.1 when doing a

doc = REXML::Document.new(xml_string)

As of now, it fails with:

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'

When changing the Header to look like:

<?xml version="1.0" encoding="utf-8"?><a><b>Something</b></a>

everything's fine. Do I miss a lib on my system, is it a known problem? Is US-ASCII invalid??

FWIW - not an answer, but I also went from JRuby 1.6.5 / Rails 3.1.3 to 1.6.7 / Rails 3.2.3 and I get the same "new" error using SimpleXML trying to parse this xml:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;simulacao&gt;&lt;ApoliceAuto Sistema=&quot;GISU&quot; Utilizador=&quot;USER&quot; 
ReferenciaExterna=&quot;16&quot; Ramo=&quot;90&quot; 
TipoSeguro=&quot;10&quot;&gt;&lt;Packs&gt;&lt;Pack 
codPack=&quot;1&quot;&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;
/Pack&gt;&lt;/Packs&gt;&lt;/ApoliceAuto&gt;&lt;/simulacao&gt;

Which looks like this (via the SO parser :) )

<?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM