Created
March 8, 2009 03:12
-
-
Save tenderlove/75553 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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