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 


arrow
arrow
    文章標籤
    perl xml parser
    全站熱搜
    創作者介紹
    創作者 Frank 的頭像
    Frank

    經驗交流分享與備忘

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