Link to home
Start Free TrialLog in
Avatar of freshgrill
freshgrill

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of parparov
parparov
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of freshgrill
freshgrill

ASKER

use XML::LibXML;
use XML::XSLT qw(serve);
use XML::DOM;
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.