LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-07-2010, 05:33 AM   #1
bharatbsharma
Member
 
Registered: Oct 2007
Posts: 33

Rep: Reputation: 15
XML::Simple usage in perl


Usin XML module i am able to read the value using statement
print "$data->{cpu}->{usr}";
But how can i read no. of child and name of child for any tag.
for example i want to find out names of all child -calls, cpu and mem - for tag <mac>.

similarly i want to find names of all child -scallPs and sreadPs-for tag <calls>.
Are they stored in some array?
Contents of xml can be unknown to me.


--------------------XML file -------------------
<mac>
<calls>
<scallPs>83234</scallPs>
<sreadPs>7462</sreadPs>

</calls>
<cpu>
<usr>10</usr>
<idle>87</idle>
</cpu>
<mem>
<freemem>5820258</freemem>
<freeswap>194320556</freeswap>
</mem>
</mac>
--------------------XML file -------------------
i am able to print xml file content
using
$data = $xml->XMLin("data.xml");
print Dumper($data);
But let me re-phrase my question like this.
by using xml parser
what statement will print : calls, cpu ,mem?
what statement will print : usr, idle
i pressume, child of any <tag> shall be stored in some array . so i can print all array element and size of the array.

thanks in advance

Last edited by bharatbsharma; 05-08-2010 at 05:40 AM. Reason: more explanation
 
Old 05-07-2010, 05:57 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by bharatbsharma View Post
Usin XML module i am able to read the value using statement
print "$data->{cpu}->{usr}";
But how can i read no. of child and name of child for any tag.
for example i want to find out names of all child -calls, cpu and mem - for tag <mac>.

similarly i want to find names of all child -scallPs and sreadPs-for tag <calls>.
Are they stored in some array?
Contents of xml can be unknown to me.


--------------------XML file -------------------
<mac>
<calls>
<scallPs>83234</scallPs>
<sreadPs>7462</sreadPs>

</calls>
<cpu>
<usr>10</usr>
<idle>87</idle>
</cpu>
<mem>
<freemem>5820258</freemem>
<freeswap>194320556</freeswap>
</mem>
</mac>
--------------------XML file -------------------

thanks in advance
Which parts of the XML file represent the data you are looking for ?
 
Old 05-07-2010, 05:57 AM   #3
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
See the Data:umper of the data_object that you get after XMLIn.
Once you see Dumped data you will have fair Idea of taking out the childs.

Code:
use Data::Dumper;
print Dumper(<xmlin_obj>)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem while installing perl xml simple on fedora 9.... Snehal.lamture Linux - Newbie 6 02-18-2009 11:25 PM
perl: simple one line replacement, simple error message! pwd_pwd_omg_pwd Programming 8 11-19-2008 12:53 PM
checking for XML::Parser... configure: error: XML::Parser perl module is required for kornerr Linux - General 11 11-16-2008 07:24 AM
LXer: XML::Simple for Perl developers LXer Syndicated Linux News 0 02-04-2007 08:21 AM
Perl XML::Simple - Hash Question smaida Programming 2 05-26-2004 04:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration