Nokogiri HttParty Xpath Ruby on Rails

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2012-10-19T22:59:33Z Indexed on 2012/10/19 23:00 UTC
Read the original article Hit count: 368

Filed under:
|
|

I am working with a mmorpg (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.

Here's an example of the response:

 <eveapi version="2"><currentTime>2012-10-19 22:41:56</currentTime><result><rowset  name="transactions" key="refID"  columns="date,refID,refTypeID,ownerName1,ownerID1,ownerName2,ownerID2,argName1,argID1,amount,balance,reason,taxReceiverID,taxAmount"><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=""/></rowset></result><cachedUntil>2012-10-19 23:03:40</cachedUntil></eveapi>

I only need to access attributes for the element "row" and there can be many rows returned.

I have read about xpath and from what I understand if I do the following it should return all rows: doc.xpath('row') however it does not return anything.

Here's what I have so far:

 options = {:keyID => 111111, :vCode => 'fddfdfdfdf'}
    response = HTTParty.post('https://api.eveonline.com/char/WalletJournal.xml.aspx', :body => options)
    doc = Nokogiri::XML(response.body)
    doc.xpath('row').each do |r|

    end

The loop is never executed.

What am I doing wrong? I need to return all row elements and gain access to each of the row's attributes.

Thanks.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby