ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 4 / 8 << | Prev | Next |
Contents > Restrictions > Error in restriction - maxOccurs

Error in restriction - maxOccurs

  1. XML Schema
XML Schema keys: maxOccurs, restriction

1. XML Schema

The "maxOccurs" of the type derived by a restriction cannot be higher than the "maxOccurs" attribute of the original type (from which it is restricted). Schema Component Constraint: Particle Derivation OK (All:All,Sequence:Sequence - Recurse), 1. .

Incorrect XML Schema (incorrect_0.xsd)


<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >

  <xsd:element name="root" type="BBB"/>

  <xsd:complexType name="AAA">
    <xsd:sequence maxOccurs="2">
      <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="BBB">
    <xsd:complexContent>
      <xsd:restriction base="AAA">
        <xsd:sequence maxOccurs="3">
          <xsd:element name="x" type="xsd:string" minOccurs="1" maxOccurs="1"/>
        </xsd:sequence>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>
</xsd:schema>