#------------------------------------------------------------------------------
# This function is to add a twig handler to remove the node in parameter
#------------------------------------------------------------------------------
sub delete_node {
#------------------------------------------------------------------------------
my ($node_to_delete,$file_to_read) = @_;
copy($file_to_read,$file_to_read.'-tmp_'.$dateLog.'.xml')
open my $file_end, '>', $file_to_read.'-parsed_'.$dateLog.'.xml'
my $handlers = {$node_to_delete => section_delete_node($file_end)};
my $twig = new XML::Twig(pretty_print => 'indented',
twig_handlers => $handlers,)->parsefile($file_to_read);
close $file_end;
if (-s $file_to_read.'-parsed_'.$dateLog.'.xml') {
move($file_to_read.'-parsed_'.$dateLog.'.xml', $file_to_read);
}
else {
move($file_to_read.'-tmp_'.$dateLog.'.xml', $file_to_read);
}
}
#------------------------------------------------------------------------------
# This function remove the node in parameter
#------------------------------------------------------------------------------
sub section_delete_node {
my ($file_end)= @_;
return sub {
my( $t, $section)= @_;
$section->delete();
$t -> flush($file_end);
}
}
####
BA
fd
Shahrara
####
BA
fd
Shahrara