针对MIcrosoft Windows任务计划程序架构的Perl XML :: Compile :: Schema

时间:2016-01-13 05:35:24

标签: xml perl

当我尝试解析Microsoft windows Task Scheduler schema时,我得到的错误类似于:

  

参数“PT1M”在/Library/Perl/5.18/XML/Compile/Schema/BuiltInFacets.pm第158行的数字ge(> =)中不是数字

我使用以下代码进行解析,当我尝试使用持续时间和持续时间范围元素的简单手写模式时,它会起作用。所以我知道该模块适用于更复杂的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);

我怀疑我没有调用必需的模块sub来容纳更复杂的Microsoft模式,但我现在很难过,我在文档中看不到任何有希望尝试下一步的内容。

更新20160114

simbabque正确地建议我应该使用严格和警告,我更新了示例代码。正如他所怀疑的那样,它没有透露任何内容,但这是最好的做法。

Mark(模块作者)怀疑错误消息实际上是由模块中的缺陷引起的,因为持续时间目前不是比较代码中的特殊情况。他之前没有在日期元素上遇到过minInclusive方面。我正在尝试组装一个在持续时间类型元素中使用minInclusive facet的最小XSD,以强制模块发出相同的错误消息。

我通过以下示例代码确认Mark的怀疑:

#!/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,并在此报告最终结果。

1 个答案:

答案 0 :(得分:1)

Mark于2016-01-15发布了XML::Compile::Schema v1.52中BuiltInFacet.pm的补丁,我确认该补丁通过了我的所有测试用例;具有minInclusive和maxInclusive facet的duration-typed元素不再导致模块抛出错误消息。非常感谢和赞美马克。

相关问题