.. i'm so slow in responding...
This is my best with your data (surely can be improved):
UPDATE: the code was broken, updated...
my $t= XML::Twig->new( pretty_print => 'indented',
twig_handlers => {
'product'=>sub{
my @pname = $_[1]->get_x
+path('name');
my @pids = $_[1]->get_xp
+ath('product_id');
print $pids[0]->text," -
+ ",$pname[0]->text,"\n";
my %h;
my @ids = $_[1]->get_xpa
+th('attributes/attribute/group/id');
my @names = $_[1]->get_x
+path('attributes/attribute/group/name');
@h{map {$_->text} @ids }
+ = map {$_->text} @names ;
my @vids = $_[1]->get_xp
+ath('attributes/attribute/value/id');
my @values = $_[1]->get_
+xpath('attributes/attribute/value/value');
@h{map {$_->text} @vids
+} = map {$_->text} @values ;
print map {"\t$_ - $h{$_
+}\n"} keys %h;
print "\n\n";
}
}
);
$t->parse($xml);
####OUTPUT
ABC123 - My product
- 12.1998
1561 - Lġngd (i mm)
1507 - Engines
1498 - Year model
12033 - Vehicle equipment
12019 - Maybe
1518 - Year model (to)
301 - Generator
XYZ789 - My product
- 12.1992
1507 - Engines
1498 - Year model
1518 - Year model (to)
301 - Generator
HtH L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
|