Last active
September 15, 2020 20:01
-
-
Save sroller/b108780e58fd4f1553e2c7603ee71756 to your computer and use it in GitHub Desktop.
Ruby: Nokogiri with XML namespace
This file contains 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
#!/usr/bin/env ruby | |
require 'pp' | |
require 'nokogiri' | |
require 'open-uri' | |
doc = Nokogiri::XML(open('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')) | |
cubes = doc.xpath("//ecb:Cube[@currency='CAD']", | |
'ecb' => 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref') | |
cubes.each { |c| | |
print c.attribute('currency'), "=", c.attribute('rate').value.to_f, "\n" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment