我希望使用Perl模块来利用一些公开的xsd文件作为模板来执行信用检查查找。
XSD文件位于:http://www.equifax.ca/XMLSchemas/UAT/
文档摘要:
“消费者和商业输入请求”的Equifax命名空间是:
- “http://www.equifax.ca/XMLSchemas/CustToEfx”表示生产环境和用户验收测试环境,也称为SS Equifax的环境。
Equifax“消费者和商业的输入请求”命名空间架构位置是:
- 适用于生产环境。
http://www.equifax.ca/XMLSchemas/Production/CNCustTransmitToEfx.xsd
- 对于用户验收测试环境,也称为Equifax的SS环境。
http://www.equifax.ca/XMLSchemas/UAT/CNCustTransmitToEfx.xsd
XML :: Compile :: Schema的文档:http://search.cpan.org/~markov/XML-Compile-1.59/lib/XML/Compile/Schema.pod
我遇到的问题是我无法正确摄取xsd文件并使用$ schema->模板(' PERL',$ type)来显示xsd模板。
(关注http://blogs.perl.org/users/brian_e_lozier/2011/10/using-xmlcompile-to-output-xsd-compliant-xml.html)
上面链接的示例代码:
#!/usr/local/bin/perl
use warnings;
use strict;
use Data::Dumper;
use XML::Compile::Schema;
use XML::LibXML::Reader;
my $xsd = 'test.xsd';
my $schema = XML::Compile::Schema->new($xsd);
# This will print a very basic description of what the schema describes
$schema->printIndex();
# this will print a hash template that will show you how to construct a
# hash that will be used to construct a valid XML file.
#
# Note: the second argument must match the root-level element of the XML
# document. I'm not quite sure why it's required here.
warn $schema->template('PERL', 'addresses');
我的尝试:
use Data::Dumper;
use XML::Compile::Schema;
use XML::LibXML::Reader;
my $xsd = '/tmp/CNCustTransmitToEfx.xsd';
my $schema = XML::Compile::Schema->new($xsd);
warn $schema->template('PERL', 'CNCustTransmitToEfx');
返回:错误:找不到元素或属性`CNCustTransmitToEfx'
$ schema-> printIndex();返回看起来不错的东西:https://pastebin.com/rkED54eV
修复以前的错误:XML::Compile does not find the root element I give it
(使用pack_type将$ type更改为{[namespace]} CNCustTransmitToEfx)
use XML::Compile::Schema;
use XML::Compile::Util qw/pack_type/;
my $schema = XML::Compile::Schema->new("/tmp/CNCustTransmitToEfx.xsd");
my $type = pack_type 'http://www.equifax.ca/XMLSchemas/CustToEfx', 'CNCustTransmitToEfx';
warn $schema->template('PERL' => $type);
返回:"错误:在{http://www.equifax.ca/XMLSchemas/CustToEfx} CNCustTransmitToEfx"
找不到类型{http://www.equifax.ca/XMLSchemas/CustToEfx} CNConsAndCommRequestType我在' CNConsAndCommRequestType'中找不到任何targetNamespace。 xsd文件,不确定这是否是问题:http://www.equifax.ca/XMLSchemas/UAT/CNConsAndCommRequestType.xsd
my $xsds = ['/tmp/CNConsAndCommRequestType.xsd','/tmp/CNCustTransmitToEfx.xsd','/tmp/CNEfxCommon.xsd','/tmp/CNConsAndCommRequestSegTypes.xsd','/tmp/BDC-CNEfxReportType.xsd', '/tmp/BDC-CNEfxTransmitToCust.xsd', '/tmp/CNCommCreditSegTypesReport2.0.xsd', '/tmp/CNCommCreditSegTypes.xsd', '/tmp/CNCommCreditTypeReport2.0.xsd','/tmp/CNCommCreditType.xsd', '/tmp/CNConsCreditSegTypes.xsd', '/tmp/CNConsCreditType.xsd', '/tmp/CNEfxReportType.xsd', '/tmp/CNEfxTransmitToCust.xsd'];
my $schema = XML::Compile::Cache->new($xsds);
my $type = pack_type 'http://www.equifax.ca/XMLSchemas/CustToEfx', 'CNCustTransmitToEfx';
warn $schema->template('PERL' => $type);
返回相同的错误:"错误:在{http://www.equifax.ca/XMLSchemas/CustToEfx} CNCustTransmitToEfx"
找不到类型{http://www.equifax.ca/XMLSchemas/CustToEfx} CNConsAndCommRequestType我很难弄清楚架构是否有问题,或者我做错了什么。
赞赏任何意见。
答案 0 :(得分:1)
我不是XML::Compile
的专家,所以我无法告诉您以下是否是最佳解决方案。我确实做出了CNConsAndCommRequestType.xsd
没有设置targetNamespace
的观察结果,但XML::Compile::Schema
允许我们覆盖它。这似乎对我有用(我在本地下载了xsd
):
use warnings;
use strict;
use XML::Compile::Schema;
use XML::Compile::Util qw/pack_type/;
my $schema = XML::Compile::Schema->new( schema_dirs=>[ '/path/to/xsds' ] );
$schema->importDefinitions($_) for qw/ CNCustTransmitToEfx.xsd
CNConsAndCommRequestSegTypes.xsd CNEfxCommon.xsd /;
$schema->importDefinitions('CNConsAndCommRequestType.xsd',
target_namespace => 'http://www.equifax.ca/XMLSchemas/CustToEfx');
my $type = pack_type('http://www.equifax.ca/XMLSchemas/CustToEfx',
'CNCustTransmitToEfx');
print $schema->template(PERL => $type);