The class Jini helps you build a XPATH.

require 'jini'
xpath = Jini
  .new
  .add_path('parent') # addition a path node
  .add_path('child') # addition a path node 
  .add_attr('key', 'value') # addition an attribute
  .to_s # convert it to a string
# -> xpath: parent/child[@key="value"]

The full list of methods is here.

Install it:

$ gem install jini

Or add this to your Gemfile:

gem 'jini'

Pay attention, it is not a parser. The only functionality this gem provides is building XPATHs.