473,480 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Parsing XML file with XML::Simple

1 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <Root>
  3.    <Item application='app1' status='Running' lastresponse='2006-11-27 10:52:47.550'>
  4.       <row index='1'>
  5.          <column_0 name='Icon'>0</column_0>
  6.          <column_1 name='Processor'>ADMIN</column_1>
  7.          <column_2 name='Status'>Active</column_2>
  8.          <column_3 name='Queued'>0</column_3>
  9.          <column_4 name='Processed'>2</column_4>
  10.          <column_5 name='Average(seconds)'>0.030</column_5>
  11.          <column_6 name='Max(seconds)'>0.050</column_6>
  12.          <column_7 name='Min(seconds)'>0.010</column_7>
  13.          <column_8 name='Last_entry'>10:48</column_8>
  14.       </row>
  15.       <row index='2'>
  16.          <column_0 name='Icon'>0</column_0>
  17.          <column_1 name='Processor'>ENQR</column_1>
  18.          <column_2 name='Status'>Active</column_2>
  19.          <column_3 name='Queued'>0</column_3>
  20.          <column_4 name='Processed'>0</column_4>
  21.          <column_5 name='Average(seconds)'>0.000</column_5>
  22.          <column_6 name='Max(seconds)'>0.000</column_6>
  23.          <column_7 name='Min(seconds)'>0.000</column_7>
  24.          <column_8 name='Last_entry'>10:48</column_8>
  25.       </row>
  26.   </Item>
  27. <Item application='app2' status='Running' lastresponse='2006-11-27 10:52:47.583'>
  28.       <row index='1'>
  29.          <column_0 name='Icon'>0</column_0>
  30.          <column_1 name='Description'>Server: app2</column_1>
  31.          <column_2 name='Last_Response'>må 2006.11.27 at 10:53:19 AM CET</column_2>
  32.          <column_3 name='Active_Sessions'>0</column_3>
  33.          <column_4 name='Invocation_Count'> </column_4>
  34.          <column_5 name='Min_(ms)'> </column_5>
  35.          <column_6 name='Max_(ms)'> </column_6>
  36.          <column_7 name='Average_(ms)'> </column_7>
  37.          <column_8 name='Total_(ms)'> </column_8>
  38.       </row>
  39.       <row index='2'>
  40.          <column_0 name='Icon'>5</column_0>
  41.          <column_1 name='Description'>   Address: 10.0.0.1</column_1>
  42.          <column_2 name='Last_Response'> </column_2>
  43.          <column_3 name='Active_Sessions'> </column_3>
  44.          <column_4 name='Invocation_Count'> </column_4>
  45.          <column_5 name='Min_(ms)'> </column_5>
  46.          <column_6 name='Max_(ms)'> </column_6>
  47.          <column_7 name='Average_(ms)'> </column_7>
  48.          <column_8 name='Total_(ms)'> </column_8>
  49.       </row>
  50. </Item>
  51. </Root>
  52.  
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:

Expand|Select|Wrap|Line Numbers
  1. use XML::Simple;
  2. use Data::Dumper;
  3. # create object
  4. $xml = new XML::Simple;
  5. # read XML file
  6. $data = $xml->XMLin("file.xml");
  7. print "$data->{application}\n";
  8. print "$data->{status}\n";

Can someone please point me in the right direction how to pull the values from this xml file ?

/John
Jan 2 '07 #1
0 1393

Sign in to post your reply or Sign up for a free account.

Similar topics

13
2259
by: Paulo Pinto | last post by:
Hi, does anyone know of a Python package that is able to load XML like the XML::Simple Perl package does? For those that don't know it, this package maps the XML file to a dictionary.
8
6473
by: Dan | last post by:
Using XML::Simple in perl is extreemly slow to parse big XML files (can be up to 250M, taking ~1h). How can I increase my performance / reduce my memory usage? Is SAX the way forward?
0
1254
by: Randy | last post by:
Is there a dotnet class that formats XML simple types. I'm making a xmldocument which has a timestamp element (among others). The format is: yyyy-MM-ddThh:mm:ss (which looks like...
6
1798
by: Lindy | last post by:
I'm using VB .Net and am brand new to XML. I need to create an XML file with the following lines: <?xml version="1.0" encoding="UTF-8" ?> - <HC_DATA...
1
1229
by: jack | last post by:
Hi all, I am working on perl..and am using XML::Simple to parse a xml document. I've been trying to retrieve character data from tags whose occurance is recursive.. The scenario can be better...
0
2098
by: Marv | last post by:
Is it possible to print the path of all leaf nodes of an XML using XML::Simple This is the kind of output text that i'm trying to print (not the leaf node values but the path to reach them) c:\>...
1
1465
by: kbozek | last post by:
I have an XSLT transform that will create an XML to XML transformation in the parent child format. I really want to output the elements and attributes on a single line such as: <image...
4
3259
by: Steven M. O'Neill | last post by:
I have an xml structure like this: <Meta name="fieldAttributes"> <MetaString name="name">SUB_PHONE</MetaString> <MetaString name="value">999999999</MetaString> </Meta> <Meta...
3
1444
by: Bilbo0a | last post by:
I am trying to save a integer array variable to a file. I am looking for the easier way to do this then going through all items and converting them to a str and then saving them as a text file. ...
0
7041
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
6929
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4481
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2995
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2984
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.