Perl XML get children

Posted on 2011-09-27
Last Modified: 2012-05-12
I have the following code, but I want to follow all the children (of the children), etc.. to printer a "flat"  complete list of elements.
$struct = $parser -> parse_file("$pid.dofiles.xml");
$rootel = $struct -> getDocumentElement();
$elname = $rootel -> getName();
print "Root element is a $elname and it contains ...\n";
@kids = $rootel -> childNodes();
foreach $child(@kids) {
$elname = $child -> getName();
@atts = $child -> getAttributes();
print "$elname (";     
foreach $at (@atts) {  
$na = $at -> getName();                                                                                                                                                                              
$va = $at -> getValue();
print " ${na}[$va] ";  
print ")\n";           

Open in new window

Question by:freshgrill
  • 2

Accepted Solution

parparov earned 500 total points
ID: 36712271
What perl module are you using? XML::Simple? XML::Parser?

Author Comment

ID: 36712298
use XML::LibXML;
use XML::XSLT qw(serve);
use XML::DOM;

Expert Comment

ID: 36712367

Now, it would greatly help if you provided a sample XML that you are parsing and the output you would like to see from it.


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now