Subject: | min/max Occurs not being passed on to children |
Date: | Mon, 01 Apr 2013 19:48:20 +0200 |
To: | bug-XML-Pastor [...] rt.cpan.org |
From: | Mirno <mirno [...] fsmail.net> |
When dealing with choice or sequences the attributes for minOccurs and maxOccurs are not being passed on to the children:
<xs:element name="outputs">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="output"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Should be identical to:
<xs:element name="outputs">
<xs:complexType>
<xs:sequence>
<xs:element ref="output" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
As such, the "output" is being treated as a singleton later on.
In XML::Pastor::Schema::Parser.pm
I've hacked a fix in by passing the parent's min & max in _processNode to the children, then in _processElement using the parent's values for min & max if they're not defined already:
sub _processElement {
my $self = shift;
my $node = shift;
my $pmin = shift;
my $pmax = shift;
my $context = $self->context();
# Create an "Element" schema model object and set all fields with the
# attributes of this node.
my $attribs = getAttributeHash($node);
$attribs->{minOccurs} = $pmin if (!defined($attribs->{minOccurs}) && defined($pmin));
$attribs->{maxOccurs} = $pmax if (!defined($attribs->{maxOccurs}) && defined($pmax));
my $obj = XML::Pastor::Schema::Element->new()->setFields($attribs);