Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Created March 8, 2009 03:12
Show Gist options
  • Select an option

  • Save tenderlove/75553 to your computer and use it in GitHub Desktop.

Select an option

Save tenderlove/75553 to your computer and use it in GitHub Desktop.
require 'nokogiri'
doc = Nokogiri::XML(<<-eoxml)
<root>
<car xmlns="http://gm.com/">
<tire>Michelin Model XGV</tire>
</car>
<bicycle xmlns="http://schwinn.com/">
<tire>I'm a bicycle tire!</tire>
</bicycle>
</root>
eoxml
puts "bike tires"
# Only find bicycle tires
doc.xpath('//bike:tire', 'bike' => 'http://schwinn.com/').each do |node|
p node
end
puts "car tires"
# Only find car tires
doc.xpath('//car:tire', 'car' => 'http://gm.com/').each do |node|
p node
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment