Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A lightweight Ruby wrapper for libxml xpath searching

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 ext
Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 Gemfile.lock
Octocat-spinner-32 LICENSE.txt
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 xpather.gemspec
README.markdown

XPather Build Status

XPather is a small Ruby wrapper for doing fast xpath searching with libxml. It doesn't go incredibly deep but offers a simple and effective api.

Installation

$ gem install xpather

Usage

XML = File.read("/test/books.xml")
document = XPather.new(XML)
=> #<XPather:0x007f9bd2a32030>

document.get("/bookstore/book[1]/author")
=> "Giada De Laurentiis"

document.get("/bookstore/book/author")
=> ["Giada De Laurentiis", "J K. Rowling", "James McGovern", "Per Bothner", "Kurt Cagle", "James Linn", "Vaidyanathan Nagarajan", "Erik T. Ray"]

document.search("/bookstore/book[1]/author")
=> ["<author>Giada De Laurentiis</author>"]

document.search("/bookstore/book/author")
=> ["<author>Giada De Laurentiis</author>", "<author>J K. Rowling</author>", "<author>James McGovern</author>", "<author>Per Bothner</author>", "<author>Kurt Cagle</author>", "<author>James Linn</author>", "<author>Vaidyanathan Nagarajan</author>", "<author>Erik T. Ray</author>"]
Something went wrong with that request. Please try again.