title: Nokogiri HttParty Xpath Ruby on Rails
body: <p>I am working with a Eve Online request that returns XML. I am using HTTParty for the request, and I am trying to use Nokogiri to obtain attribute values for a specific element.</p>
  
  <p>Here's an example of the response:</p>
  
  <pre><code> &lt;eveapi version="2"&gt;&lt;currentTime&gt;2012-10-19 22:41:56&lt;/currentTime&gt;&lt;result&gt;&lt;rowset  name="transactions" key="refID"  columns="date,refID,refTypeID,ownerName1,ownerID1,ownerName2,ownerID2,argName1,argID1,amount,balance,reason,taxReceiverID,taxAmount"&gt;&lt;row date="2012-10-18 23:41:50" refID="232323" refTypeID="9" ownerName1="University of Caille" ownerID1="32232" ownerName2="name" ownerID2="34343" argName1="" argID1="0" amount="5000.00" balance="5000.00" reason="Starter fund" taxReceiverID="" taxAmount=""/&gt;&lt;/rowset&gt;&lt;/result&gt;&lt;cachedUntil&gt;2012-10-19 23:03:40&lt;/cachedUntil&gt;&lt;/eveapi&gt;
  </code></pre>
  
  <p>I only need to access attributes for the element "row" and there can be many rows returned.</p>
  
  <p>I read about XPath and, from what I understand, if I do the following it should return all rows: <code>doc.xpath('row')</code> however, it does not return anything.</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>options = {:keyID =&gt; 111111, :vCode =&gt; 'fddfdfdfdf'}
  response = HTTParty.post('https://api.eveonline.com/char/WalletJournal.xml.aspx', :body =&gt; options)
  doc = Nokogiri::XML(response.body)
  doc.xpath('row').each do |r|
  
  end
  </code></pre>
  
  <p>The loop is never executed.</p>
  
  <p>What am I doing wrong?  I need to return all row elements and gain access to each of the row's attributes.</p>
  
  <p>Here's the code I had before, which worked until I tried a different character and received a "cannot convert integer to string error":</p>
  
  <pre><code>options = {:keyID =&gt; 434343, :vCode =&gt; 'fdfdfdfdf'}
  response = HTTParty.post('https://api.eveonline.com/char/WalletJournal.xml.aspx', :body =&gt; options)
  data = response.parsed_response
  data['eveapi']['result']['rowset']['row'].each do |t|
    if t['ownerName2'].eql?('name') &amp;&amp; !t['reason'].eql?('Starter fund')
      uniqueKey = t['ownerID1'].to_s + t['date']
      if !Payment.exists?(:unique_payment_key =&gt; uniqueKey)
        p = Payment.new
        p.owner_id = t['ownerID1']
        p.owner_name = t['ownerName1']
        p.unique_payment_key = uniqueKey
        p.amount = t['amount']
        p.reason = t['reason']
        p.save
      end
    end
  end
  </code></pre>
  
  <p>Sorry, the error is <code>error: can't convert String into Integer online line 42</code> which is</p>
  
  <pre><code>if t['ownerName2'].eql?('name') &amp;&amp; !t['reason'].eql?('Starter fund')
  </code></pre>