【发布时间】:2018-08-23 13:05:15
【问题描述】:
我希望使用 Perl 模块来利用一些公开可用的 xsd 文件作为模板来执行信用检查查找。
XSD 文件在这里:http://www.equifax.ca/XMLSchemas/UAT/
文档sn-p:
“消费者和商业的输入请求”的 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->template('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' xsd 文件中找不到任何 targetNamespace,不确定这是否是问题:http://www.equifax.ca/XMLSchemas/UAT/CNConsAndCommRequestType.xsd
第三次尝试:先在本地添加所有 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”
我很难确定这是架构有问题还是我做错了什么。
感谢任何输入。
【问题讨论】: