views:

460

answers:

1

I am using Nokogiri 1.3.3 with Ruby 1.8.7 I am trying to match the content of a tag as described in this SO question:

nodeset.xpath("entry/index[. = '#{index.to_s}']/../categories")

Nokogiri raises an exception complaining about the '.' after the bracket. When I replace the '.' with text() it then complains about the second period. Is this me or Nokogiri? How do I fix it

+1  A: 

If I understand your document structure correctly, you should be able to do:

nodeset.xpath("entry[index='#{index.to_s}']/categories")

which seems more readable to me.

Greg Campbell
Ok, But my example is a valid xpath why will it not parse? This is not the only time this has come up.
John F. Miller
Odd - your exact xpath works for me (Nokogiri 1.3.3, Ruby 1.8.6 and/or 1.9.1). What version of libxml2 are you using?
Greg Campbell