ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 3 / 8 << | Prev | Next |
Contents > Restrictions > Error in restriction - non-matching types

Error in restriction - non-matching types

  1. XML Schema
XML Schema keys: type, restriction

1. XML Schema

When restrictions are made, the types must be mapped correctly. Roughly said, we cannot declare element "x" to be a string and then declare it as an "integer" in the restriction. Schema Component Constraint: Particle Derivation OK (All:All,Sequence:Sequence - Recurse), 2. .

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="1">
          <xsd:element name="x" type="xsd:integer" minOccurs="1" maxOccurs="1"/>
        </xsd:sequence>
      </xsd:restriction>
    </xsd:complexContent>
  </xsd:complexType>
</xsd:schema>