On Thu, 24 Apr 2008 10:34:58 -0500, Ken Bloom wrote:

> On Wed, 23 Apr 2008 17:17:32 -0700, Stedwick wrote:
> 
>> I have this line in my XML file that was created by REXML
>> 
>> <episode name='03x08 - Future&apos;s End ~ 1' rating='100'>
>> 
>> And I simply cannot access that element using REXML, at all, in any
>> way, no matter what, as far as I can tell...
>> 
>> I have tried escaping the apostrophes, I have tried converting them to
>> &apos;, I have tried both directly accessing the element and using
>> XPath, nothing works.
>> 
>> Does anybody have any tricks for how to access elements that have
>> attributes with apostrophes in their names? Thanks!
> 
> This has been discussed at
> http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/117253
> 
> 
> When will REXML support parameterized XPath queries (the way *all* SQL
> databases support parameterized SQL queries)?
> 
> --Ken

I spoke too soon. I found it, thought it's just a little short of being 
documented. (Somehow, when generating Ruby 1.8 docs for ruby-doc.org, 
RDoc didn't extract the variables parameter.)

Consider the following:

doc=REXML::Document.new open("appraisal.xml")
node=REXML::XPath.first doc, '//lexeme[phrase/text()=$name]',
    {}, {"name"=>"n't"}
puts node

<lexeme>
    <phrase>n't</phrase>
    <entry domain='appraisal'>
      <modify att='orientation' type='flip'/>
      <set att='polarity' value='marked'/>
      <modify att='force' type='flip'/>
    </entry>
  </lexeme>

However, this doesn't work with
doc.elements['//lexeme[phrase/text()=$name]',{"name"=>"n't"}]
which returns nil.

-- 
Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/