我正在尝试运行 Perl 脚本以将 xml 文档的所有元素放入一个数组中。代码如下:
#!/usr/bin/perl
# Script to illustrate how to parse a simple XML file
# and dump its contents in a Perl hash record.
use strict;
use XML::Simple;
my $xs = new XML::Simple();
my $booklist = $xs->XMLin('./cmn_msg.xml');
print Dumper($data);
当我运行这段代码时,出现错误:
Use of tied on a handle without * is deprecated at C:/Perl/lib/XML/Parser/Expat.pm line 447.
not well-formed (invalid token) at line 4, column 14, byte 128 at C:/Perl/lib/XML/Parser.pm line 187
我正在使用为 MSWin32-x86-多线程构建的 ActivePerl (v5.14.1)。 我正在尝试在 Win7 上运行此脚本。
最佳答案
But when I run this code, I get an error: Use of tied on a handle without * is deprecated at C:/Perl/lib/XML/Parser/Expat.pm line 447.
这听起来像是警告,而不是错误。您安装的 XML::Parser: 已过期。
not well-formed (invalid token) at line 4, column 14, byte 128 at C:/Perl/lib/XML/Parser.pm line 187
那表示您的 XML 已损坏。您需要更正 XML。
关于xml - 使用 Perl XML::Simple 时出现“格式不正确”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7145957/