Skip to content

Instantly share code, notes, and snippets.

@sroller
Last active September 15, 2020 20:01
Show Gist options
  • Save sroller/b108780e58fd4f1553e2c7603ee71756 to your computer and use it in GitHub Desktop.
Save sroller/b108780e58fd4f1553e2c7603ee71756 to your computer and use it in GitHub Desktop.
Ruby: Nokogiri with XML namespace
#!/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