use strict;
use warnings;
use XML::Twig;
my $start = time;
my $flag = 0;
open my $fout1, '>', "XMLTest1.csv";
open my $fout2, '>', "XMLTest2.csv";
my $twig = XML::Twig - > new(
twig_roots => {
'Misc' => 1, 'Profession' =>1,'Actor' =>1,'Age' =>1
},
twig_handlers => {
'Database' => sub {
my($twig, $el) = @_;
$twig - > purge;
},
'Database//*' => sub {
print $fout2 $_ - > tag, ",", unless(($_ - > has_children('#ELT')) || ($flag = 1));
print $fout1 $_ - > text, ",", unless($_ - > has_children('#ELT'));
$flag = 1;
}
}
);
$twig - > parsefile('Actors.xml');
my $duration = time - $start;
print "Execution time: $duration s\n";
####
|Profession|Actor |Age|Music|TV|Music|TV|
|Actor |Ben Affleck|43 |none|Pearl Harbor|none|2001|
|Actor |Ben Affleck|43 |Jenny from the block|Wood Will Hunting|2002|1997|
.
.
.
.
|Actor |Leonardo DiCaprio|41|None|Saturday Night Live|None|2014|
####
-
Actors
-
-
Ben Affleck
43
USA
-
Jennifer Garner
Seraphina Rose
-
-
Chasing Amy
Gigli
Dogma
-
Field of dreams
None
-
Shakespeare in Love
None
-
-
none
Pearl Harbor
-
none
2001
-
Jenny from the block
Good Will Hunting
-
2002
1997
-
Johnny Depp
52
USA
-
Amber Heard
Lilly Rose
-
-
Mortdecai
Rango
What's eating gilbert grape
-
Edward Scissorhands
Alice in Wonderland
-
Chocolat
None
-
-
The Snake
The Run Diary
-
1994
2011
-
Be Here Now
21 Jump Street
-
1997
1987
-
Leonardo DiCaprio
41
USA
-
None
None
-
-
The Wolf of Wall Street
What's Eating Gilbert Grape
Don's Plum
-
Inception
None
-
Titanic
Romeo+Juliet
-
-
None
Shutter Island
-
None
2011
-
None
Saturday Night Live
-
None
2014