Adam Teale wrote:
> hi Guys,
>
> I have a tab-delimited text file that I would like to convert into an
> xml file that can be read/imported into Apple's Final Cut Pro.
>
> The text file is 2 columns.
> The first column is the time (timecode)
> The second column is text (for sub-titling)
Could you send us 2 example files? I guess the text file format is
obvious (but better to work with a real-life example) but I am not so
sure about the Final Cut Pro XML (or is it just a plain simple XML?)
Until then, check out this code:
================================================== ==========
input = <<INPUT
0.12 Salut, Foo!
0.15 Hola Bar! Did you see Baz?
0.22 I guess he is hanging around with Fluff and Ork.
INPUT
template = <<TEMPLATE
<timecode>TIMECODE</timecode>
<sub-titling>SUB-TITLING</sub-titling>
TEMPLATE
result = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
input.split(/\n/).each do |line|
data = line.split(/\t/)
result += template.sub('TIMECODE'){data[0]}.sub('SUB-TITLING'){data[1]}
end
result += '</xml>'
puts result
================================================== ==========
output:
<?xml version="1.0" encoding="ISO-8859-1"?>
<timecode>0.12</timecode>
<sub-titling>Salut, Foo!</sub-titling>
<timecode>0.15</timecode>
<sub-titling>Hola Bar! Did you see Baz?</sub-titling>
<timecode>0.22</timecode>
<sub-titling>I guess he is hanging around with Fluff and
Ork.</sub-titling>
</xml>
Cheers,
Peter
__
http://www.rubyrailways.com