Fixing a "bad" XML File

Joe Kline

Purdue.pm

[Palm Pre and FitTrack]

Palm Pre App Launch screen FitTrack app top half screen FitTrack app bottom half screen
[any material that should appear in print but not on the slide]

[Generates a GPX file]

[any material that should appear in print but not on the slide]

[Not a valid GPX 1 format]

[any material that should appear in print but not on the slide]

[Problem 1: I'm paranoid]

[any material that should appear in print but not on the slide]

[Problem 2: I'm cheap]

FitTrack app HP app store entry
[any material that should appear in print but not on the slide]

[So I wrote some code]

#!/usr/bin/env perl

use strict;
use warnings;

use 5.012;

use XML::Twig;
use DateTime;
use Date::Parse;
[any material that should appear in print but not on the slide]

[So I wrote some code, continued]

#
# change time format from: 
#    Mon Feb 06 2012 19:51:42 GMT-0500 (EST)
# to 2012-02-06T16:50:52Z
#
my ($file) = @ARGV;

my $twig= XML::Twig->new(
    PrettyPrint   => 'record',
    twig_handlers => { time => \&time_fix }
);
$twig->parsefile($file);
[any material that should appear in print but not on the slide]

[So I wrote some code, continued]

$twig->print();
exit(0);

sub time_fix {
    my ($twig, $time_element) = @_;
    my $wrong_format = $time_element->text ();
    my $time = str2time($wrong_format);
    my $date = DateTime->from_epoch( epoch => $time);
    $date = $date . q(Z);
    $time_element->set_text ($date);
}
[any material that should appear in print but not on the slide]

[The Files]

[any material that should appear in print but not on the slide]