From: "NAKAMURA, Hiroshi" Date: 2005-04-30T11:27:44+09:00 Subject: Re: [QUIZ] Barrel of Monkeys (#30) Hi all, Sorry for OT & advertising. Bill Guindon wrote: > On 4/29/05, Ruby Quiz wrote: > >>You can find an XML file with over 5,000 song names and play time at >>http://rubyquiz.com/SongLibrary.xml.gz (100k compressed). The song durations are >>in milliseconds. > > Any suggestions for an easy to use XML library? Or for that matter, > is it ok to convert it to another format? Personally, I'd prefer CSV > or YAML (hate the extra baggage that comes with XML). With the latest snapshot of soap4r, you can parse that like this; 0% irb irb(main):001:0> require 'zlib' => true irb(main):002:0> gz = Zlib::GzipReader.new(File.open("SongLibrary.xml.gz")) => # irb(main):003:0> require 'xsd/mapping' => true irb(main):004:0> library = XSD::Mapping.xml2obj(gz.read); nil => nil irb(main):005:0> library.Artist.size => 1004 irb(main):006:0> library.Artist.find { |artist| artist.xmlattr_name = "ABBA" }.Song.collect { |song| song.xmlattr_name } => ["Caught Up In You", "Fantasy Girl", "Hold On Loosely", "Second Chance", "Teacher, Teacher", "Back Where You Belong", "The Sound of Your Voice"] xml2obj generates singleton object for each XML element (It means you can't Marshal.dump it. ). Regards, // NaHi