From: Sandy Thomson Date: 2009-03-18T00:47:47+09:00 Subject: Re: XML to CSV with REXML - I'm sure this should be easy... Robert Klemme wrote: > > Here you need to iterate through all the "performance" elements _below > the current event_ and concatenate the individual performance's date > with what you have built so far. > > You should probably also take measures to emit a line without a date in > case zero performances can be found in input XML. > > > Kind regards > > robert Thank you Robert, I'm getting closer... I modified it as below, but for some reason the dates are now stacking up on each other as so: 1234|Event Title|Event Category|Venue Name|1 Some Street|Some Town|2009-04-01 18:00:00 1234|Event Title|Event Category|Venue Name|1 Some Street|Some Town|2009-04-01 18:00:00|2009-04-03 18:00:00 So, I'm still missing something - any ideas? xml.elements.each("//event") do |e| detail = ( e.attributes['id'] << "|" << e.elements['title'].text << "|" << e.elements['category'].text << "|" << e.elements['venue/name'].text << "|" << e.elements['venue/address/address1'].text << "|" << e.elements['venue/address/town'].text ) xml.elements.each("//performances/performance") do |f| csv_file.puts detail << "|" << f.attributes['date'] end end -- Posted via http://www.ruby-forum.com/.