App to query Web API/XML

11 views
Skip to first unread message

L V Lammert

unread,
Aug 2, 2012, 5:49:22 PM8/2/12
to stl...@googlegroups.com
Looking at doing a small CLI app to query a web API, parse the returned data, then query again for each item returned. All data is XML, .. so any recommendation on what would be the best starting point? Builder? REXML? XmlSimple?

    Thanks!

    Lee

Jeff Barczewski

unread,
Aug 3, 2012, 1:18:43 PM8/3/12
to stl...@googlegroups.com
Lee,

I haven't been keeping up with the state of the art in Ruby lately, but nokogiri and hpricot both were able to parse XML and you could use xpath or css style selectors to parse xml. I really like the flexibility of using selectors.

I tried this on small xml parsing project once and the code was pretty simple and worked well for my use case.

All the best,

Jeff

Anthony F

unread,
Aug 3, 2012, 2:14:21 PM8/3/12
to stl...@googlegroups.com
nokogiri isn't the quickest, but its easy, a task from an app I wrote:

desc "Fetch weather"
task :fetch_weather => :environment do
          require 'nokogiri'
          require 'open-uri'
          require 'pp'

            @weathers = Weather.all
            @weathers.each do |weather|

        begin
            url = "SomeURL"
            doc = Nokogiri::XML(open(url))
            data = Hash.from_xml(doc.to_s)
            puts weather.zip


            puts  "Current Dewpoint: #{data["ArrayOfWeatherData"]["WeatherData"][0]["DewPointF"]}"






--
You received this message because you are subscribed to the Google Groups "Saint Louis Ruby Users Group" group.
To view this discussion on the web visit https://groups.google.com/d/msg/stlruby/-/JPyXniicG5oJ.
To post to this group, send email to stl...@googlegroups.com.
To unsubscribe from this group, send email to stlruby+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/stlruby?hl=en.

Reply all
Reply to author
Forward
0 new messages