【发布时间】:2016-02-06 03:56:55
【问题描述】:
我正在尝试使用以下脚本将 xml 文件转换为 csv
#!/usr/local/bin/perl
use strict;
use warnings;
use XML::Twig;
my $twig = XML::Twig->new()->parsefile ( 'test.xml' );
print "id;name;description;published\n";
foreach my $row ( $twig->results->children('row') ) {
print join( ";",
$row->first_child_text('id'),
$row->first_child_text('name'),
$row->first_child_text('description'),
$row->first_child_text('published'),
),
"\n";
}
但我在 perl1.pl 第 10 行通过包“XML::Twig”收到错误 Can't locate object method "results”。
这是我的 xml
<results>
<row>
<id></id>
<name>...</name>
<description>...</description>
<published></published>
</row>
....
</result>
【问题讨论】: