Skip to content
A lightweight Ruby wrapper for libxml xpath searching
Ruby C
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
ext/xpather Added xml_str function to return the contents of @xml_str
lib
test Return [] if nothing found in search
.gitignore Make rake test work properly
.travis.yml Adding travis ci config
Gemfile
Gemfile.lock
LICENSE.txt
README.markdown
Rakefile
xpather.gemspec Put rake in the gem dependencies

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.