From: Paul Lutus Date: 2006-12-06T18:10:09+09:00 Subject: Re: Newbie: working with a text file and converting to xml Adam Teale wrote: > Hi Kev & Peter! > > Thanks for respoding so quickly! > > The text file looks pretty much like that > > 00:00:30:13 Swayambhunath Temple: building started 460AD > 00:00:42:21 Durbar Square > 00:01:05:06 Driving to Trisuli River for Rafting > 00:01:55:22 Day 1 Trekking: Pokhara to Tirkhedhunga (1540m) > 00:02:20:20 Day 2 Trekking: Tirkhedhunga to Ghorephani (2750m) > 00:02:33:19 Day 3 Trekking: Ghorephani to Ghandruk (1940m) > 00:02:42:04 Day 4 Trekking: Ghandruk to Pothana (1900m) > 00:03:10:13 Day 5 Trekking: Pothana to Phedi (1130m) > > It'll take a while for your example to filter down into my brain - when > it does I'll get back to you about it. -------------------------------------------- #!/usr/bin/ruby -w data =<<__EOL__ 00:00:30:13 Swayambhunath Temple: building started 460AD 00:00:42:21 Durbar Square 00:01:05:06 Driving to Trisuli River for Rafting 00:01:55:22 Day 1 Trekking: Pokhara to Tirkhedhunga (1540m) 00:02:20:20 Day 2 Trekking: Tirkhedhunga to Ghorephani (2750m) 00:02:33:19 Day 3 Trekking: Ghorephani to Ghandruk (1940m) 00:02:42:04 Day 4 Trekking: Ghandruk to Pothana (1900m) 00:03:10:13 Day 5 Trekking: Pothana to Phedi (1130m) __EOL__ output = "\n" data.each do |line| timecode,subtitle = line.strip.split("\t") xml = "#{timecode}#{subtitle}" output += xml + "\n" end File.open("output.xml","w") { |f| f.write output } -------------------------------------------- The data block at the top can easily be replaced with a file reader line: data = File.read(filename) -- Paul Lutus http://www.arachnoid.com