Hi all,
How to use XML:Twig print to print to a file and how to use delete to delete
an element?
For print to a file: I tired what FAQ says but it doesn't work, the file
size is always 0. Belows are my codes:
#!/usr/bin/perl
use warnings;
use strict;
use XML::Twig;
my $twig= XML::Twig->new( twig_roots => {Topic => 1},
twig_handlers => { 'RDF/Topic' => &topic }
);
$twig->parsefile( './content.example.txt');
{
open(FH, ">diet.xml") or die "cannot open diet.xml: $!";
my $count = 0;
sub topic {
my ($twig, $topic) = @_;
if ($topic->children('link') or $topic->children('link1')){ #this if
subroutine is used for output <Topic/> with <link(1)/> elements only
$twig->print(*FH);
}
$twig->purge;
}
close FH;
}
Many many thanks,
Nan