Perl 读写XML文档

!/usr/bin/perl

use XML::Simple;
use Data::Dumper;

@arr = [

    {'country'=>'england', 'capital'=>'london'},
    {'country'=>'norway', 'capital'=>'oslo'},
    {'country'=>'india', 'capital'=>'new delhi'} ];

create object

my $xml = new XML::Simple (NoAttr=>1, RootName=>'data');
my $data = $xml->XMLout(@arr);

print Dumper($data);

print ($data);

open (FNS ,“> D:\PerlDemo\ff.xml”);
print FNS ($data);
close (FNS);

<log version="0.1" date="2009-04-14">
    <change>describes about version 0.1</change>
</log>
<log version="0.2" date="2009-04-15">
    <change>describes about version 0.2</change>
</log>

my $conf = XMLin(“D:\PerlDemo\parse.xml”);

print “Program \n $conf->{'name'}
$conf->{'author'} $conf->{'mail'}\n”;

my $i = 0;
while( $conf->{'log'}->[$i] )
{

print "\@ $conf->{'log'}->[$i]->{'version'} at " .
 "$conf->{'log'}->[$i]->{'date'} : " . 
 "$conf->{'log'}->[$i]->{'change'}\n";
$i ++;

}

你可能感兴趣的:(Perl 读写XML文档)