#!/usr/bin/perl -w use strict; use XML::Parser; use File::Basename; use HTML::Entities; my $transcript; my $curNode; my $curText; my $url; print "Content-type: text/plain\n\n"; sub handle_start { my ($expat, $type, %data) = @_; #print '<' . $type . '>'; $curNode = $type; $curText = ''; if ($type eq 'transcription') { $transcript = ''; undef $url; } elsif ($type eq 'panel') { $transcript .= '
'; } elsif ($type eq 'line') { $transcript .= '
'; } } sub handle_char { my ($expat, $text) = @_; $curText .= $text; } sub handle_end { my ($expat, $type) = @_; #print $curText . '\n"; if ($type eq 'url') { $url = $curText; } elsif ($type eq 'transcription') { my ($name,$path,$suffix) = fileparse($url, ".php"); print "Writing $url => $name\n"; open TS, '>', $name . ".ts" or die "Could not open $path.ts: $@"; print TS $transcript; close TS; } elsif ($type eq 'line') { $transcript .= encode_entities($curText) . "
\n"; } elsif ($type eq 'panel') { $transcript .= '
'; } undef $curText; } my $parser = new XML::Parser(Handlers => {Start => \&handle_start, End => \&handle_end, Char => \&handle_char}); open XML, '<', 'ohnorobot.xml' or die "Could not open file: $@"; $parser->parse(*XML, ProtocolEncoding => 'ISO-8859-1');