Try building a hash from the name/value elements within each resourceGroup. Example using XML::Twig
#!/usr/bin/perl
use strict;
use XML::Twig;
#time|resourceGroup name|LCONNFAIL|LLOSTCONN|LIDLETIMEOUT|SIPADDR|SIPP
+ORT
my @columns = ('resourceGroup',
'LCONNFAIL','LLOSTCONN','LIDLETIMEOUT','SIPADDR','SIPPORT');
my $time;
my %record = ();
# tag handler
my $twig = XML::Twig->new(
twig_handlers =>
{
resourceGroup => \&resourceGroup,
statistic => \&statistic,
},
start_tag_handlers => {
statRecord => sub { $time = $_[1]->att('time') }
}
);
# process file
print join '|','time',@columns;
print "\n";
$twig->parsefile( 'my_file.xml' );
sub resourceGroup {
my ($t,$e) = @_;
$record{'resourceGroup'} = $e->att('name');
# print record
print join "|",$time,map{$record{$_}}@columns;
print "\n";
$t->purge;
%record = ();
}
sub statistic {
my ($t,$e) = @_;
my $name = $e->first_child_text('name');
$record{$name} = $e->first_child_text('value');
}
poj