3

我想使用 XML::Schematron::LibXSLT 验证 XML 文件,这是我尝试使用 .sch 模式文件和 XML 文件作为参数的代码

use XML::Schematron::LibXSLT;

my $schema_file = $ARGV[0];
my $xml_file    = $ARGV[1];

die "Usage: perl schematron.pl schemafile XMLfile.\n"
    unless defined $schema_file and defined $xml_file;

my $tron = XML::Schematron::LibXSLT->new();

$tron->schema($schema_file);
my $ret = $tron->verify($xml_file);

print $ret . "\n";

它给出Can't locate object method "new" via package "XML::Schematron::LibXSLT" at schematron.pl line 14.了告诉模块没有新方法的错误。可能是模块已更新。

所以我也试过

use XML::Schematron;

my $pseudotron = XML::Schematron->new_with_traits( traits => ['LibXSLT'], schema => "$schema_file");
my $messages = $pseudotron->verify($xml_file);

print "$messages\n";

但它不打印任何东西。不知道怎么回事!

同样在https://metacpan.org/pod/XML::Schematron::LibXSLT Synopsis,第二次和第三次使用给出了相同的错误。

请参阅perlmonk链接以及同一篇文章

4

0 回答 0