Sorry, may be I was unclear. What happens is: the xml that is sent back contains something like "cheese & coffee" so this breaks REXML, and since the call to REXML's method is made from the ActiveResource object itself we are unable to customize how REXML's initialize method is called. When I modified the line "cheese & coffee" to "cheese & coffee" everything works fine. So I am pretty sure this issue is being caused because of the unescaped ampersand that is contained in the xml. But I cannot modify the xml content as it comes to me from a third party source over which we have no control. Here is the stack trace that might help clearing up things: <code> --- !ruby/exception:REXML::ParseException message: |- #<RuntimeError: Illegal character '&' in raw string "cheese & coffee "> /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/text.rb:91:in `initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:43:in `new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/parsers/treeparser.rb:43:in `parse' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/document.rb:227:in `build' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rexml/document.rb:43:in `initialize' /Users/mxx/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/xml_mini/rexml.rb:17:in `new' /Users/mxx/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/xml_mini/rexml.rb:17:in `parse' (__DELEGATION__):2:in `__send__' (__DELEGATION__):2:in `parse' /Users/mxx/.gem/ruby/1.8/gems/activesupport-2.3.2/lib/active_support/core_ext/hash/conversions.rb:154:in `from_xml' /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/formats/xml_format.rb:19:in `decode' /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/connection.rb:116:in `get' /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:587:in `find_one' /Library/Ruby/Gems/1.8/gems/activeresource-2.3.2/lib/active_resource/base.rb:522:in `find' </code> How can we change what parser is being used by Rails. I would definitely like to try out Nokogiri but am unsure about how to make it work with Rails (2.3.2) and in specific with ActiveResource though. Eric Hodel wrote: > On Aug 24, 2009, at 15:18, Engine Yard wrote: > >> Did anyone actually find out a solution to this issue. >> >> I have an ActiveResource object which returns back some xml content >> (as >> a result of a web service call) with unescaped "& " and this causes >> the >> same issue. > > These two statements are contradictory. It can't both be XML and have > unescaped &. > >> Wondering if we can customize the method call to >> REXML::Text.initialize() and set raw=>false. >> >> Tried to change the setting in the REXML library that comes with the >> Ruby distribution, but that did not help. >> >> Is there a way to overcome this issue without patching any of Ruby or >> Rails code. I cannot change the content on the web service server. > > > Use a parser that handles errors: > > $ ruby -rubygems -e 'require "nokogiri"; d = Nokogiri::XML "<foo>&<bar/ > ></foo>"; p d.errors; p d' > [#<Nokogiri::XML::SyntaxError: xmlParseEntityRef: no name > >] > <?xml version="1.0"?> > <foo> > <bar/> > </foo> > > $ > > PS: The name on your email account is odd. -- Posted via http://www.ruby-forum.com/.