1

I am pretty green with coding in Ruby but am trying to pull an XML feed into a Ruby object:

<% doc = Nokogiri::XML(open("http://api.workflowmax.com/job.api/current?apiKey=#{@feed.service.api_key}&accountKey=#{@feed.service.account_key}")) %>

<% doc.xpath('//Jobs/Job').each do |node| %>
    <h2><%= node['name'].text %></h2>
    <p><%= node['description'].text %></p>
<% end %>

Basically, I want to iterate through each Job and output the name, description etc.

What am I missing?

2
  • I would suggest separating logic and presentation. You should have your XMl parsing in the Controller. You also should make it asyn, since you dont know how long the feed requesting/parsing going to take. Other than that what problem do you get? An error of some kind? Empty page? Commented May 20, 2010 at 22:52
  • What happens if you replace .text with .content? Otherwise being able to see a sample of the XML would help a bit too Commented May 22, 2010 at 20:43

1 Answer 1

5

Well, since you haven't shown us any sample XML, I'm going to go out on a limb and say that it is not likely the description is in an attribute. You've used the syntax to extract 'name' and 'description' attributes from the 'job' element. If instead they are nested elements you want something like this:

<% doc.xpath('//Jobs/Job').each do |node| %>
    <h2><%= node.xpath('name').inner_text %></h2>
    <p><%= node.xpath('description').inner_text %></p>
<% end %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.