Ticket #145 (new defect)

Opened 5 months ago

Last modified 5 months ago

XPath and undefined method `filter[@[=]]'

Reported by: gonzoprosperity Owned by: why
Priority: major Milestone:
Component: ext/hpricot_scan Version:
Keywords: Cc:

Description

I am trying to parse an XML file generated by Google Analytics. When I run my script from a bare-bones ruby script it works just fine, but when I take the same logic and try running it under a Rails app (either via an HTTP request, script/runner OR script/console) I get a stack dump.

My XPath is:

doc.search("//itemsummary[@id='PageviewsSummary?']/summaryvalue")

And the stack trace is:

/Users/cody/Projects/cakestreet_trunk/vendor/rails/railties/lib/commands/runner.rb:47: undefined method `filter[@[=]]' for #<Hpricot::Elem:0x302c350> (NoMethodError?)

from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/elements.rb:307:in `filter' from /Users/cody/Projects/cakestreet_trunk/vendor/rails/activerecord/lib/../../activesupport/lib/active_support/inflector.rb:250:in `find_all' from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/elements.rb:305:in `each' from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/elements.rb:305:in `find_all' from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/elements.rb:305:in `filter' from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.6/lib/hpricot/traverse.rb:310:in `search' from /Users/cody/Projects/cakestreet_trunk/lib/analytics_xml_parser.rb:12:in `parse' from /Users/cody/Projects/cakestreet_trunk/lib/analytics_xml_parser.rb:19

... 10 levels...

from script/runner:3:in `eval' from /Users/cody/Projects/cakestreet_trunk/vendor/rails/railties/lib/commands/runner.rb:47 from script/runner:3:in `require' from script/runner:3

Attached is my basic Ruby script with the XPath (and the above stack trace)

Thanks in advance.

Attachments

analytics_xml_parser.rb (1.6 kB) - added by gonzoprosperity 5 months ago.
Basic ruby script with XPath and stack dump

Change History

Changed 5 months ago by gonzoprosperity

Basic ruby script with XPath and stack dump

Changed 5 months ago by gonzoprosperity

As a follow-up with some platform notes:

Hpricot 0.6 on OS X 10.5 running under Ruby 1.8.6

Changed 5 months ago by gonzoprosperity

Just to be clear: I can run the above script straight from the command line and it works no problem. Placing the script in RAILS_ROOT/lib and then executing "ruby script/runner AnalyticsXmlParser?" results in the above issue.

The script is the same, its just the calling environment that changes.

Note: See TracTickets for help on using tickets.