Handling XML in Perl example from a Well House Consultants training course
#!/usr/bin/perl
use XML::LibXML;
$parser = new XML::LibXML;
$struct = $parser -> parse_file("apps-admin.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";
}
More on Handling XML in Perl [link]
Or refer to http://mkweb.bcgsc.ca/intranet/perlbook/pxml/ch06_04.htm
留言列表