【发布时间】:2016-01-15 19:02:08
【问题描述】:
当我尝试解析 Microsoft windows Task Scheduler schema 时,我收到类似于以下内容的错误:
/Library/Perl/5.18/XML/Compile/Schema/BuiltInFacets.pm 第 158 行的数字 ge (>=) 中的参数“PT1M”不是数字
我使用以下代码进行解析,当我尝试针对使用持续时间和持续时间范围元素的简单手写模式时,该代码有效。所以我知道该模块适用于更复杂的 Microsoft 架构,而且它一定是我使用它的方式。
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
use XML::Compile::Schema;
use XML::Compile::Util qw/pack_type/;
my $schema = XML::Compile::Schema->new( "task-scheduler-ms.xsd" );
my $type = pack_type 'http://schemas.microsoft.com/windows/2004/02/mit/task', 'Task';
my $elem = pack_type 'http://schemas.microsoft.com/windows/2004/02/mit/task', 'Task';
$schema->printIndex;
my $read = $schema->compile(READER => $elem);
我怀疑我没有调用必需的模块子来适应更复杂的 Microsoft 架构,但我现在很难过,我在文档中看不到任何有希望尝试下一步的内容。
更新 20160114
simbabque 正确地建议我应该使用严格和警告,我更新了示例代码。正如他所怀疑的那样,它并没有透露任何信息,但这是最好的做法。
Mark(模块作者)怀疑错误消息实际上是由模块中的缺陷引起的,因为持续时间目前不是比较代码中的特殊情况。他以前没有在日期元素上遇到过 minInclusive 方面。我正在尝试组装一个最小 XSD,它在持续时间类型的元素中使用 minInclusive 方面来强制模块发出相同的错误消息。
我用下面的示例代码证实了马克的怀疑:
#!/usr/bin/perl
use strict;
use warnings;
use XML::LibXML;
use XML::Compile::Schema;
use XML::Compile::Util qw/pack_type/;
my $schema = XML::Compile::Schema->new( "duration-range-example-2.xsd" );
my $type = pack_type 'http://tempuri.org/durationExample', 'Duration';
my $elem = pack_type 'http://tempuri.org/durationExample', 'Duration';
$schema->printIndex;
my $read = $schema->compile(READER => $elem);
使用以下示例数据:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://tempuri.org/durationExample">
<xs:element name="Duration" default="PT10M" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:duration">
<xs:minInclusive value="PT1M"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
这会产生以下输出:
namespace: http://tempuri.org/durationExample
filename: duration-range-example-2.xsd
definitions of elements:
Duration
Argument "PT1M" isn't numeric in numeric ge (>=) at /Library/Perl/5.18/XML/Compile/Schema/BuiltInFacets.pm line 158.
Argument "PT10M" isn't numeric in numeric ge (>=) at /Library/Perl/5.18/XML/Compile/Schema/BuiltInFacets.pm line 158.
如果可行,我将与 Mark 跟进解决问题,并在此处报告最终结果。
【问题讨论】:
-
欢迎使用 Stack Overflow 和 Perl 标签。请确保在此处提问或回答时始终使用
use strict和use warnings,因为这将有助于更轻松地诊断很多问题,尽管在这里可能不会很明显。