#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
my $parser = XML::LibXML->new;
my $doc = $parser->parse_file('./tv.xml');
my $result = $doc->findnodes('//programme');
while ( my $node = $result->shift ) {
unless ( $node->hasAttribute('stop') ) {
# Om vi har ett äldre syskon, använd 'start' tid som 'stop' tid
if ( my $next = $result->get_node(1) ) {
$node->setAttribute( 'stop', $next->getAttribute('start') );
}
}
}
$doc->toFile( './tv_fixed.xml', 1 );
I koden använder jag modulen XML::LibXML som i sin tur är beroende av libxml
303 ms totalt · 4 externa anrop · v20260731065814-full.2f471f9e