PerlでXMLドキュメントを読み書くサンプルコード
Perlコード:
!/usr/bin/perl
use XML::Simple;
use Data::Dumper;
@arr = [
{'country’=>’日本’, 'capital’=>’東京’},
{'country’=>’韓国’, 'capital’=>’ソウル’},
{'country’=>’中国’, 'capital’=>’北京’} ];
//オブジェクトを作成(create object)
my $xml = new XML::Simple (NoAttr=>1, RootName=>’data’);
my $data = $xml->XMLout(@arr);
print Dumper($data);
print ($data);
open (FNS ,“> D:\startnews24\perldemo.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:\startnews24\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 ++;
}