Re: simpleContent restriction: Xerces vs xmlspy and turboxml

Hi Paul,

>    <element name="FormattedName" minOccurs="0" maxOccurs="unbounded">
>     <complexType>
>      <simpleContent>
>       <restriction base="string">
>        <attribute name="type" default="presentation">
>         <simpleType>
>          <restriction base="string">
>           <enumeration value="presentation"/>
>           <enumeration value="legal"/>
>           <enumeration value="sortOrder"/>
>          </restriction>
>         </simpleType>
>        </attribute>
>       </restriction>
>      </simpleContent>
>     </complexType>
>    </element>
>
> I can see why one could say that using <extension> rather then
> <restriction> better models what is happening here, but I don't see
> where this is considered invalid. Whom would you say is correct
> Xerces or XMLSPY and TurboXML?

The above is definitely invalid. When you derive by restriction the
resulting complex type must allow less things than the base complex
type. So you cannot *add* an attribute to the content model of a
complex type when you derive by restriction.

Probably the people from XMLSpy and TurboXML are basing their claims
on the XML structure - the fact that <attribute> elements are legal
within <restriction> elements within a <simpleContent> element.
However, it's the fact that the base attribute of the <restriction>
points to a simple type definition that makes it invalid.

This is covered in several places within the XML Schema Rec:

  Schema Representation Constraint: Complex Type Definition
  Representation OK

  2. If the <simpleContent> alternative is chosen, the type
     definition ·resolved· to by the ·actual value· of the base
     [attribute] must be either a complex type definition whose
     {content type} is a simple type definition or, only if the
     <extension> alternative is also chosen, a simple type definition;

In the above, the type definition resolve to by the value of the base
attribute is not a complex type definition.

Also in:

  Schema Component Constraint: Complex Type Definition Properties
  Correct

  2. If the {base type definition} is a simple type definition, the
     {derivation method} must be extension.

In the above, the base type definition is a simple type definition,
but the derivation method is restriction.

Also in:

  Schema Component Constraint: Derivation Valid (Restriction, Complex)

  If the {derivation method} is restriction all of the following must
  be true:
  1. The {base type definition} must be a complex type definition
     whose {final} does not contain restriction.
  
In the above, the derivation method is restriction, but the base type
definition is not a complex type definition.
  
If you swapped <restriction> for <extension> it would be perfectly
fine.

Cheers,

Jeni

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

Received on Monday, 19 November 2001 16:00:23 UTC