Here is some code I wrote a while back that will do a recursive walk through a zip file that contains another zip and so on, to any depth. This code just prints the content, but the $unzip object at the line that says "Deal with the payload here" is just a filehandle, so if the xml parser accepts a filehandle it can be passed to it.
This code also has the advantage that it doesn't involve storing either the complete compressed or uncompressed data in memory. It streams all data as needed.
#!/usr/bin/perl
use warnings;
use strict;
use IO::Uncompress::Unzip;
sub walk
{
my $name = shift;
my $fh = shift;
my $indent = shift // 0 ;
$indent += 2;
my $unzip = new IO::Uncompress::Unzip $fh,
or die "Cannot open zip\n" ;
my $status;
for ($status = 1; $status > 0; $status = $unzip->nextStream())
{
my $name = $unzip->getHeaderInfo()->{Name};
warn " " x $indent . "Processing member $name\n" ;
if ($name =~ /.zip$/)
{
walk($name, $unzip, $indent);
}
else
{
# Deal with the payload here
my $buff;
while (($status = $unzip->read($buff)) > 0) {
# Do something here
print "$buff\n";
}
}
last if $status < 0;
}
die "Error processing $name: $!\n"
if $status < 0 ;
}
my $file = shift;
my $fh ;
open $fh, "<$file" ;
warn "Processing zip file $file\n";
walk($file, $fh);
|