Hi all,
I have just started working with the XML::Simple module to parse an XML file.
I'm trying to pull some values from the file that I need in another program.
The problem is that the XML file is "nested" and I can't get the correct values out of the file.
This is part of my xml file:
I'm trying to pull out the application name and status and eventually all the columns to construct a plain "comma separated" file.
I have tried using the XML::Simple module to read the file but I can't get it to parse this file properly.
This is my code:
Can someone please point me in the right direction how to pull the values from this xml file ?
/John
I have just started working with the XML::Simple module to parse an XML file.
I'm trying to pull some values from the file that I need in another program.
The problem is that the XML file is "nested" and I can't get the correct values out of the file.
This is part of my xml file:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Root>
<Item application='app1' status='Running' lastresponse='2006-11-27 10:52:47.550'>
<row index='1'>
<column_0 name='Icon'>0</column_0>
<column_1 name='Processor'>ADMIN</column_1>
<column_2 name='Status'>Active</column_2>
<column_3 name='Queued'>0</column_3>
<column_4 name='Processed'>2</column_4>
<column_5 name='Average(seconds)'>0.030</column_5>
<column_6 name='Max(seconds)'>0.050</column_6>
<column_7 name='Min(seconds)'>0.010</column_7>
<column_8 name='Last_entry'>10:48</column_8>
</row>
<row index='2'>
<column_0 name='Icon'>0</column_0>
<column_1 name='Processor'>ENQR</column_1>
<column_2 name='Status'>Active</column_2>
<column_3 name='Queued'>0</column_3>
<column_4 name='Processed'>0</column_4>
<column_5 name='Average(seconds)'>0.000</column_5>
<column_6 name='Max(seconds)'>0.000</column_6>
<column_7 name='Min(seconds)'>0.000</column_7>
<column_8 name='Last_entry'>10:48</column_8>
</row>
</Item>
<Item application='app2' status='Running' lastresponse='2006-11-27 10:52:47.583'>
<row index='1'>
<column_0 name='Icon'>0</column_0>
<column_1 name='Description'>Server: app2</column_1>
<column_2 name='Last_Response'>må 2006.11.27 at 10:53:19 AM CET</column_2>
<column_3 name='Active_Sessions'>0</column_3>
<column_4 name='Invocation_Count'> </column_4>
<column_5 name='Min_(ms)'> </column_5>
<column_6 name='Max_(ms)'> </column_6>
<column_7 name='Average_(ms)'> </column_7>
<column_8 name='Total_(ms)'> </column_8>
</row>
<row index='2'>
<column_0 name='Icon'>5</column_0>
<column_1 name='Description'> Address: 10.0.0.1</column_1>
<column_2 name='Last_Response'> </column_2>
<column_3 name='Active_Sessions'> </column_3>
<column_4 name='Invocation_Count'> </column_4>
<column_5 name='Min_(ms)'> </column_5>
<column_6 name='Max_(ms)'> </column_6>
<column_7 name='Average_(ms)'> </column_7>
<column_8 name='Total_(ms)'> </column_8>
</row>
</Item>
</Root>
I have tried using the XML::Simple module to read the file but I can't get it to parse this file properly.
This is my code:
Code:
use XML::Simple;
use Data::Dumper;
# create object
$xml = new XML::Simple;
# read XML file
$data = $xml->XMLin("file.xml");
print "$data->{application}\n";
print "$data->{status}\n";
Can someone please point me in the right direction how to pull the values from this xml file ?
/John