Click to See Complete Forum and Search --> : parsng large xml file with perl


ktpmm5
March 10th, 2008, 08:57 AM
I have a large xml output file with data that repeats for each entity it comes across, like below:

'timeResult' => [
{
'success' => 'false',
'connection' => 'eth1',
'portResponse' => 'OK',
'ns5:snmpType' => {
'cd5:targetType' => 'eth',
'name' => 'string1',
'cd5:protocol' => 'udp',
},
'localTime' => '2008-12-04T'
}

The section above repeats about 10 times per file (once for each host tested). I have successfully parsed the beginning section (getting the values of success, localTime, and portResponse) with the code below, but I can't figure out how to get to the 'snmpType' area, and put targetType, name and protocol into variables. Can someone help me to figure out what I need to do? thank you-

use XML::XPath;
#
## create object
my $xml = XML::XPath->new(filename => '/sources/sample.xml');
#
foreach my $row ($xml->findnodes('/touchResult/scanResult')) {

my $success = $row->find('success')->string_value;
my $portResponse = $row->find('portResponse')->string_value;
my $localTime = $row->find('localTime')->string_value;
....;
}

PeejAvery
March 11th, 2008, 07:02 PM
[ moved ]

PeejAvery
March 11th, 2008, 07:07 PM
I'm not a PERL expert, but since it is just another dimension/node, can't you call findnodes() on the snmpType nodes?