elva

perl 把xml文件转换成csv文件

#!/usr/local/bin/perl

# use module
use XML::Simple;
use Data::Dumper;

# create object
$xml = new XML::Simple;

# read XML file
$data = $xml->XMLin("DebugInfo.xml", ForceArray => 1);

# print output
#print Dumper($data);
#print Dumper($data->{'employee'}[0]);
#print Dumper($data->{'employee'}[1]);

$data1=$data->{'DebugInfo'};

#print @{$data1};
open FILE,">>debug.log";
foreach $item (@{$data1}){
print FILE "${$item}{UID}[0],";
print FILE "${$item}{ChannelID}[0],";
print FILE "${$item}{IPAddress}[0],";
if (${$item}{BufferMapString}[0] =~/^HASH/)
{print FILE ",n";}
else{print FILE "${$item}{BufferMapString}[0]n"};
}
close FILE;

posted on 2008-08-11 19:34 叶子 阅读(3068) 评论(0)  编辑 收藏 引用 所属分类: UnixXML


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理