Hi Markov :-)
We upgraded to 0.97 today and immediately had a problem with our schema
failing to compile messages that had a minOccurs="0": we've worked
around in the one failing case... but it could manifest itself in other
cases too...
Gareth and I investigated, and have found that the problem seems to be
while processing the containing <xs:sequence> BLOCK. The latest version
of XC defaults to min=1, even though the contained block is intended to
be optional.
The attached test case with an extract from our schema should make this
clear - but please let me know if there are additional tests or
information that I can provide to help debug!
Thanks for providing X::C and for any time that you have to help resolve!
Hakim
Subject: | xml-compile.t |
#!/usr/bin/perl
use strict; use warnings;
use Data::Dumper;
use XML::Compile::Schema;
use XML::Compile::Translate::Writer;
use XML::LibXML;
=head1 NAME
Bug report minOccurs for L<XML::Compile>
=head2 Worked in
0.64-0.69
=head2 Broken in
0.97
=head2 Reported by
hakim@thermeon.com, 2008-12-15
=cut
use Test::More tests=>2;
use Test::Exception;
my $schema = do { local $/=undef; <DATA> };
my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
my %hash = (
'ResRates' => {
'Count' => 4,
'Messages' => { 'Message' => [
{
number => 12,
type => 'Error',
Text => 'Example'
}
] }
}
);
test_xml( "Sanity check", $schema, $doc, \%hash );
$hash{ResRates}{Messages}{Message} = []; # this should be fine too (as Message is numOccurs="0")
test_xml( "With zero messages", $schema, $doc, \%hash );
sub test_xml {
my ($desc, $schema_data, $doc, $hash) = @_;
my $schema = XML::Compile::Schema->new( $schema_data );
my $write = $schema->compile(
WRITER => '{http://www.thermeon.com/webXG/xml/webxml/}Response',
use_default_prefix => 1,
);
lives_ok {
my $xml = $write->($doc, $hash);
# diag $xml->toString;
} $desc;
}
__DATA__
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Revision: 1060 $ -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.thermeon.com/webXG/xml/webxml/"
xmlns="http://www.thermeon.com/webXG/xml/webxml/"
elementFormDefault="qualified">
<xs:element name="Response">
<xs:complexType>
<xs:choice>
<xs:element name="ResRates">
<xs:complexType>
<xs:sequence>
<xs:element name="Count" type="xs:int" />
<xs:element name="Messages" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Message" type="MessageType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:complexType name="MessageType">
<xs:sequence>
<xs:element name="Text" type="xs:string"/>
</xs:sequence>
<xs:attribute name="number" type="xs:string" use="optional"/>
<xs:attribute name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Question" />
<xs:enumeration value="Info" />
<xs:enumeration value="Warning" />
<xs:enumeration value="Error" />
<xs:enumeration value="Critical" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
<xs:complexType name="MessagesType">
<xs:sequence>
<xs:element name="Message" type="MessageType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:schema>