Re: Complex type inheritance is evil!

Hi Alex,

> I am using Xerces 1.4.1 to parse the following XML (see below), against the
> XML schema (see below also)
>
> am getting the following error message...
>
> Error writing attributes: Error validating data: | Validation Error on Line
> 1.  URI: null  Message: Schema error: Anonymous complexType:
> ct-props-correct.2: The type 'xs:string' is a simple type.  It cannot be
> used in a derivation by RESTRICTION for a complexType.
>
> Does any one have any ideas??? i am stumped? XML Spy 4 seems to think every
> think is OK, although this is using the MSXML3.dll SP1 parser ( I think)
>
>         <xs:element name="BasisForChoice">
>                 <xs:complexType>
>                         <xs:simpleContent>
>                                 <xs:restriction base="xs:string">
>                                         <xs:attribute name="Duid"
> type="xs:ID"/>
>                                         <xs:attribute name="Euid"
> type="xs:string"/>
>                                         <xs:attribute name="Rank"
> type="xs:string"/>
>                                 </xs:restriction>
>                         </xs:simpleContent>
>                 </xs:complexType>
>         </xs:element>
>

Xerces is correct and XML Spy is wrong in this case. The problem is in the above
element declaration and the problem is that you have used a simpleType as the
base type in a complexType definition derived by restriction which is not valid.
Instead you need to extend the simpleType xs:string by adding an attribute. So,
change <xs:restriction> to <xs:extension> and everything should work fine.

Cheers,
/Eddie

Received on Sunday, 2 September 2001 20:19:59 UTC