From: Ezra Zygmuntowicz Date: 2005-05-01T10:28:44+09:00 Subject: Re: [QUIZ] Barrel of Monkeys (#30) --Apple-Mail-6--835254283 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Apr 29, 2005, at 7:27 PM, NAKAMURA, Hiroshi wrote: > 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 > Hey I am t6rying to play with this xml2object method but when I do a require 'xsd/mapping' it fails. What library is xsd/mapping ? Where do I get it or is it supposed top be in the core? Thanks- -Ezra --Apple-Mail-6--835254283--