I am having trouble understanding the output from the perl schema complier, it appears that in some cases the maxOccurs indicator is ignored. If I try to use a complex element more than once, the first reference seems correct, however subsequent references are output as arrays even when the maxOccurs indicator is set to "1". I only started playing with xml schemas, so my understanding is very limited.
I have to following schema (sorry, I tried to cut it down as much as possible):
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://ift.tt/tphNwY">
<xs:element name="Top">
<xs:complexType>
<xs:sequence>
<xs:element ref="Foo" minOccurs="0" maxOccurs="1"/>
<xs:element ref="Bar" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Foo">
<xs:complexType>
<xs:sequence>
<xs:element ref="Bar" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Bar">
<xs:complexType>
<xs:attribute name="Baz" use="optional" />
</xs:complexType>
</xs:element>
</xs:schema>
When I run:
perl -MXML::Compile::Schema -e 'print XML::Compile::Schema->new("example.xsd")->template("PERL", "Top");'
I get the following output:
# is an unnamed complex
{ # sequence of Foo, Bar
# is an unnamed complex
# is optional
Foo =>
{ # sequence of Bar
# is an unnamed complex
# is optional
Bar =>
{ # is a xs:anyType
# becomes an attribute
Baz => "anything", }, },
# is an unnamed complex
# complex structure shown above
# is optional
Bar => [{},], }
"Bar" as an element of Foo appears as a complex (as expected), However "Bar" under the top level appears and list of complex, even though maxOccurs="1" (not what I am expecting). Is my understanding just wrong or is my schema incorrect?
No comments:
Post a Comment