Perl XML get children

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

freshgrillAsked:
Who is Participating?
 
parparovConnect With a Mentor Commented:
What perl module are you using? XML::Simple? XML::Parser?
0
 
freshgrillAuthor Commented:
use XML::LibXML;
use XML::XSLT qw(serve);
use XML::DOM;
0
 
parparovCommented:
OK.

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.



0
All Courses

From novice to tech pro — start learning today.