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 


文章標籤
創作者介紹

經驗交流分享與備忘

Frank 發表在 痞客邦 PIXNET 留言(0) 人氣()