Given a valid XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="personinfo">
<xs:complexType>
<xs:sequence maxOccurs="2">
<xs:element name="firstname" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
For a valid XML against this XSD, a <personinfo>
should contain max 2 sequence of <firstname>
followed by <lastname>
. I add minOccurs
and maxOccurs
to firstname
. For an XML file below:
<personinfo>
<firstname>lalal</firstname>
<lastname>fwfw</lastname>
<firstname>lalal</firstname>
<lastname>fwfw</lastname>
</personinfo>
Why is it still valid by validator? Don't minOccurs
and maxOccurs
just overwrite the maxOccurs
by xs:sequence
?