Re: What are complexContent restrictions made for ?

Hi Anton,

>> Thus, deriving by restriction is helpful because it enables you to
>> express the commonality between a set of elements, and process them
>> in the same kind of way.
>
> As I understand the idea of derivation is the following:
> If type B is derived from type A then every element of type B can be
> considered as an element of type A.

That's true for derivation by restriction. It's illegal to try to
derive a type by restriction and for that *not* to be true.

> However, type definitions can be as follows:
>
> <xs:complexType name="A">
>     <xs:sequence>
>         <xs:element name="child" type="xs:string" minOccurs="1"
> maxOccurs="1"/>
>     </xs:sequence>
> </xs:complexType>
>
> <xs:complexType name="B">
>     <xs:complexContent>
>         <xs:restriction base="A">
>             <xs:sequence>
>                 <xs:element name="child" type="xs:string" minOccurs="0"
> maxOccurs="0"/>
>             </xs:sequence>
>         </xs:restriction>
>     </xs:complexContent>
> </xs:complexType>
>
> If I have element of actual type B, but think of it as of element of
> type A then I will fail trying to get value of its element <child>.
> Please, correct me if I am wrong.

That's not a valid derivation by restriction, because you've broken
the rule that every element of the derived type (B) has to be valid
against the base type (A). Specifically, you've restricted an element
with a minimum and maximum occurrence of 1 to an element with a
minimum and maximum occurrence of 0. This is illegal according to
clauses 1 and 2.2 of Schema Component Constraint: Occurrence Range OK:

  For a particle's occurrence range to be a valid restriction of
  another's occurrence range all of the following must be true:
  1 Its {min occurs} is greater than or equal to the other's {min occurs}.
  2 one of the following must be true:
  2.1 The other's {max occurs} is unbounded.
  2.2 Both {max occurs} are numbers, and the particle's is less than
      or equal to the other's.
                            http://www.w3.org/TR/xmlschema-1/#range-ok

A schema validator should reject the schema.
                            
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Saturday, 18 May 2002 17:00:55 UTC