Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save SeanTAllen/663525 to your computer and use it in GitHub Desktop.
Save SeanTAllen/663525 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'nokogiri'
frag = Nokogiri::XML.fragment( '<p id="content">hi</p>' )
path = './/p'
ns = {}
handler = nil
ctx = Nokogiri::XML::XPathContext.new(frag.children.first)
puts "As XML-Element/first child..."
puts ctx.evaluate(path, handler)
ctx = Nokogiri::XML::XPathContext.new(frag)
puts "As XML-DocumentFragment..."
puts ctx.evaluate(path, handler)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment