All the instances of the new restricted type must also be valid for the base type. But in your schema, it is possible to define a RestrictedPasswordType
which does not have a Length
attribute (minOccurs="0"
), which would be illegal for the base type minOccurs="1"
. Making an element optional is not a restriction of the base type.
Removing minOccurs='0'
from Generation
is OK because having at least one element is a restriction.
Additionally your restriction references the Length
element, which is not the same as the Length
element defined in the base type. The Length
element is of LengthType
according to the base schema, and the Length
element in the base type is a RestrictedLengthType
which is a restriction of LengthType
.
I believe that if you change the <xs:element>
declaration in your derived type to:
<xs:element name="Length" type="RestrictedLengthType" minOccurs="1"/>
it should work, unless there are other problems.
EDIT: the other problems:
Since a new element Length
is being declared in the <complexType>
block, it needs to be declared as "qualified"
otherwise it will not be part of the targetNamespace
and the restriction will fail. To fix this you can either:
- Add a
form="qualified"
attribute to<xs:element name="Length" ... />
, or - Add an
elementFormDefault="qualified" attribute to the
` element.
More information here:
- About constraints for redefinitions: XML Schema Part 1 - 4.2 Layer 2: Schema Documents, Namespaces and Composition
- About qualified elements and target namespaces: XML Schema Primer - 3 Advanced Concepts I: Namespaces, Schemas & Qualification