473,545 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
+ 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 1404

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

Similar topics

13
2272
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
6485
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
1262
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 2003-09-28T07:55:06). The schema looks like: <xsd:simpleType name="TimestampType"> <xsd:annotation> <xsd:documentation>Base typefor a date and time...
6
1806
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 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://.../asc.xsd"> other stuff... </HC_DATA>
1
1235
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 explained as below: For a structure like, <employees> <employee>
0
2117
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:\> perl ListLeafs.pl config.xml {RootNode}->{ChildNode1}->{LeafNode1} {RootNode}->{ChildNode1}->{LeafNode2} {RootNode}->{ChildNode1}->{LeafNode3}...
1
1469
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 name="car.jpg" size="5000" /><image type = "jpg" compression = "20" /> .... ....
4
3269
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 name="fieldAttributes"> <MetaString name="name">SUB_NAME</MetaString> <MetaString name="value">XML PLUS</MetaString>
3
1449
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. All data transaction is only done in the array and not on the file. so its just to dump the data onto a file and read it back into the array next...
0
7487
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7934
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5349
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4966
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3476
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
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 we have to send another system
1
1033
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
731
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.