From: Francis Hwang Date: 2004-10-21T11:48:53+09:00 Subject: Escaping single quotes in XPath query with REXML Anybody tried to use XPath in REXML with a single quote, only to run into the fact that quote escaping in XPath is apparently not accounted for? If this were in the context on XSLT I'd be able to assign some annoying temp variable like $apos, but it's not, so I can't. irb(main):001:0> require 'rexml/document' => true irb(main):002:0> include REXML => Object irb(main):003:0> xml = "John's Doe" => "John's Doe" irb(main):004:0> xmldoc = Document.new xml => ... irb(main):005:0> XPath.first( xmldoc, "/rss/channel/item/title" ).to_s => "John's Doe" irb(main):006:0> XPath.first( xmldoc, "/rss/channel/item/title[text()='John's Doe']" ).to_s NoMethodError: undefined method `node_type' for "John":String from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:124:in `internal_parse' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:123:in `each' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:123:in `internal_parse' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:49:in `match' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:402:in `Predicate' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:346:in `Predicate' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:204:in `internal_parse' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:199:in `times' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:199:in `internal_parse' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:49:in `match' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:34:in `parse' from /usr/local/lib/ruby/1.8/rexml/xpath.rb:28:in `first' from (irb):6 irb(main):007:0> XPath.first( xmldoc, "/rss/channel/item/title[text()='John\'s Doe']" ).to_s NoMethodError: undefined method `node_type' for "John":String from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:124:in `internal_parse' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:123:in `each' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:123:in `internal_parse' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:49:in `match' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:402:in `Predicate' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:346:in `Predicate' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:204:in `internal_parse' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:199:in `times' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:199:in `internal_parse' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:49:in `match' from /usr/local/lib/ruby/1.8/rexml/xpath_parser.rb:34:in `parse' from /usr/local/lib/ruby/1.8/rexml/xpath.rb:28:in `first' from (irb):7