当我尝试使用XML::Simple读取 XML 文件时,有时会收到以下错误消息:
无法为文件创建文件解析器上下文...
经过一番谷歌搜索,这似乎是libxml-libxml-perl 的问题,应该在我使用的版本(1.59-2)中得到修复。
有任何想法吗?
编辑:(代码)
sub Read
{
my ($file, $no_option) = @_;
my %XML_INPUT_OPTIONS = ( KeyAttr => [], ForceArray => 1 );
if ((defined $file) && (-f $file))
{
my @stats = stat($file);
if ((defined $XML_CACHE{$file})
&& ($stats[9] == $XML_CACHE{$file}{modif_time}))
{
return ($XML_CACHE{$file}{xml});
}
else
{
my $xml = eval { XMLin($file,
(defined $no_option ? () : %XML_INPUT_OPTIONS)) };
AAT::Syslog("AAT::XML", "XML_READ_ERROR", $@) if ($@);
$XML_CACHE{$file}{modif_time} = $stats[9];
$XML_CACHE{$file}{xml} = $xml;
return ($xml);
}
}
return (undef);
}
是的,我应该 & 将使用XML::Simple缓存功能...