Query (remote) XML documents with XPath
Latest commit ba4b04e Feb 26, 2016 @gioele State support for BaseX
Failed to load latest commit information.
lib basex: Manually wrap results Feb 18, 2015
spec Enable CodeClimate Jan 19, 2015
.gitignore Initial code May 15, 2014
.travis.yml Enable CodeClimate Jan 19, 2015
COPYING Initial code May 15, 2014
Gemfile Initial code May 15, 2014
README.md State support for BaseX Feb 26, 2016
Rakefile Initial code May 15, 2014
xpathquery.gemspec Enable CodeClimate Jan 19, 2015


XPathQuery: query (remote) XML documents with XPath

XPathQuery offers a uniform interface to make queries on XML documents that are local, remote or stored on a XML database. Different XPath backends are supported (right now BaseX, eXist-db and Nokogiri).


The main use of XPathQuery is to query remote XML databases without dealing with the details such as request envelopes, deserialization and so on.

# first we set up the query engine
require 'xpathquery/exist'
xml_remote = XPathQuery::Exist.new('http://localhost:8080/exist/rest/db')

# then we perform the query and we get back an array of XML nodes
results = xml_remote.query('//patron')
results.map { |result| p result.class }
# => [Nokogiri::XML::Element, Nokogiri::XML::Element, ...]

Namespaces are supported and are simple to use

ns = { 'foaf' => 'http://xmlns.com/foaf/0.1/' }
results = xml_remote.query('//foaf:name', ns)

Rails logger integration

If a logger is supplied during the engine initialization it will be used to log the queries made and the results received.

The Rails logger can be easily integrated passing Rails.logger to the engine constructor.

xml = XPathQuery::Exist.new('http://localhost:8080/...', logger: Rails.logger)

The messages will be logged at the :debug level.


The xpathquery gem depends on the nokogiri gem, even when the Nokogiri engine is not used.

Additionally, the BaseX and eXist-db backends depend on the rest_client gem. If you want to use these backends, you must install the rest_client gem, because it is not a direct dependency of the xpathquery and RubyGems does not have the concept of "optional dependency".

This gem requires a modern Ruby implementation as MRI 2.1, JRuby or Rubinious.


gem install xpathquery



Code : http://svario.it/xpathquery (redirects to GitHub)

Report issues : http://svario.it/xpathquery/issues

Documentation : http://svario.it/xpathquery/docs


This is free software released into the public domain (CC0 license).

See the COPYING file or http://creativecommons.org/publicdomain/zero/1.0/ for more details.