title: Reading an XML file with Nokogiri in Rails 3
body: <p>I have a problem trying to loop through part of an XML file. I'm using Nokogiri with Rails3. </p>
  
  <p>I'm reading this XML feed - <a href="http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml" rel="nofollow">http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml</a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>def save_rates
  
      # get the XML data form ECB URL
      file_handle = open('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml')
  
      # get document xml string and create Nokogiri object
      doc = Nokogiri::XML(file_handle)
  
      # foreach date...
      doc.xpath("//Cube/Cube").each do |cube|
  
          raise cube.inspect # isn't being executed
  
          # foreach currency...
          cube.xpath("./Cube").each do |curr|
              # create DB entry
              Exchange.create(:currency=&gt;curr.currency, :rate=&gt;curr.rate, :record_date =&gt; cube.time)
  
          end
      end
  
  end
  </code></pre>
  
  <p>When I inspect <code>doc</code> I can see the Nokogiri object. However when I try to raise <code>cube.inspect</code> inside the first .each loop it just isn't firing. So it's lead me to believe my path is wrong: <code>//Cube/Cube</code>.</p>
  
  <p>From other example I have seen in Nokogiri tutorials the paths are similar to that. Is my path wrong or is there something else I've done wrong here? </p>
  
  <p>I'm ruby n00b so please go easy!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here is the format of the XML</p>
  
  <pre><code>&lt;gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"&gt;
      &lt;gesmes:subject&gt;Reference rates&lt;/gesmes:subject&gt;
      &lt;gesmes:Sender&gt;
      &lt;gesmes:name&gt;European Central Bank&lt;/gesmes:name&gt;
      &lt;/gesmes:Sender&gt;
      &lt;Cube&gt;
          &lt;Cube time="2013-02-25"&gt;
              &lt;Cube currency="USD" rate="1.3304"/&gt;
              &lt;Cube currency="JPY" rate="125"/&gt;
              &lt;Cube currency="BGN" rate="1.9558"/&gt;
              &lt;Cube currency="CZK" rate="25.52"/&gt;
              &lt;Cube currency="DKK" rate="7.4614"/&gt;
              &lt;Cube currency="GBP" rate="0.8789"/&gt;
              ...
          &lt;/Cube&gt;
          &lt;Cube&gt;
          &lt;Cube time="2013-02-24"&gt;
              &lt;Cube currency="USD" rate="1.3304"/&gt;
              &lt;Cube currency="JPY" rate="125"/&gt;
              &lt;Cube currency="BGN" rate="1.9558"/&gt;
              &lt;Cube currency="CZK" rate="25.52"/&gt;
              &lt;Cube currency="DKK" rate="7.4614"/&gt;
              &lt;Cube currency="GBP" rate="0.8789"/&gt;
              ...
          &lt;/Cube&gt;
      &lt;/Cube&gt;
  &lt;/gesmes:Envelope&gt;
  </code></pre>