tenderlove/nokogiri — Issue #607: JRuby - RubyStringIO#path - NoMethodError 
Author: mindscratch
Created: 2012-02-01 02:04:19+00:00
State: open

I'm using JRuby 1.6.5 with Ruby 1.9 compatibility and Nokogiri 1.5.0 (java). I attempted to parse an XML document using MultiXml (which defaulted to using Nokogiri as its parse) but I got a NoMethodError raised in [document.rb](https://github.com/tenderlove/nokogiri/blob/master/lib/nokogiri/xml/document.rb#L25).

Apparently in JRuby 1.6.5 (and even 1.6.6) the "path" method in org/jruby/RubyStringIO [raises a NoMethodError](https://github.com/jruby/jruby/blob/master/src/org/jruby/ext/stringio/RubyStringIO.java#L527) when using Ruby 1.9 (when using Ruby 1.8.x the path method just returns nil).

My work around was to monkey patch Document.rb with the following code:

````ruby
# in a file named nokogiri_monkey_patch.rb that I load when I startup my app

class Nokogiri::XML::Document
def self.parse string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block
options = Nokogiri::XML::ParseOptions.new(options) if Fixnum === options
# Give the options to the user
yield options if block_given?

doc = if string_or_io.respond_to?(:read)
path = nil
if string_or_io.respond_to?(:path)
begin
path = string_or_io.path
rescue NoMethodError
end
end
url ||= path
read_io(string_or_io, url, encoding, options.to_i)
else
# read_memory pukes on empty docs
return new if string_or_io.nil? or string_or_io.empty?
read_memory(string_or_io, url, encoding, options.to_i)
end

# do xinclude processing
doc.do_xinclude(options) if options.xinclude?

return doc
end
````