Page 1 of 1

E derivation-ok-restriction.5.4.2

Posted: Wed Jan 25, 2006 5:55 pm
by alk
Hi,

I'm having the subsequent XSD, where I try to apply a restriction to the complex type AUPriceType:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="AUPriceType">
<xs:sequence>
<xs:element name="Carrier" minOccurs="0">
<xs:complexType>
<xs:attribute name="Code" type="xs:string" use="optional"/>
<xs:attribute name="Original" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="AdultAbsoluteValue" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="TotalDuration" type="xs:short" use="optional"/>
<xs:attribute name="NightsOfStay" type="xs:short" use="optional"/>
<xs:attribute name="Amount" type="xs:positiveInteger" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="SeasonChar" type="xs:string" use="optional"/>
<xs:attribute name="SeasonCharRef" type="xs:string" use="optional"/>
</xs:complexType>
<xs:complexType name="PricesType">
<xs:sequence>
<xs:element name="Price" maxOccurs="unbounded">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="AUPriceType">
<xs:sequence>
<xs:element name="Carrier" minOccurs="0" maxOccurs="0">
<xs:complexType>
<xs:attribute name="Code" type="xs:string" use="optional"/>
<xs:attribute name="Original" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="AdultAbsoluteValue" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="TotalDuration" type="xs:short" use="prohibited"/>
<xs:attribute name="NightsOfStay" type="xs:short" use="optional"/>
<xs:attribute name="Amount" type="xs:positiveInteger" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="SeasonChar" type="xs:string" use="prohibited"/>
<xs:attribute name="SeasonCharRef" type="xs:string" use="optional"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
When trying to validate I receive the error messages:
Position: 25:21
E rcase-Recurse.2: There is not a complete functional mapping between the particles.
URL: http://www.w3.org/TR/xmlschema-1/#rcase-Recurse

Position: 25:21
E derivation-ok-restriction.5.4.2: Error for type '#AnonType_PricePricesType'. The particle of the type is not a valid restriction of the particle of the base.
URL: http://www.w3.org/TR/xmlschema-1/#deriv ... estriction
Any help on the problem is truly appreciated. Tanks in advance for your help!!

Regards
Alex

Posted: Wed Jan 25, 2006 7:11 pm
by george
Hello Alex,

The problem is that the complex type for the Price element cannot be derived from the AUPriceType because the AdultAbsoluteValue element is locally defined and has unrelated types. The relevant place in the specification is:

http://www.w3.org/TR/xmlschema-1/#rcase-NameAndTypeOK
3.2.5 R's {type definition} is validly derived given {extension, list, union} from B's {type definition} as defined by Type Derivation OK (Complex) (§3.4.6) or Type Derivation OK (Simple) (§3.14.6), as appropriate.
Note: The above constraint on {type definition} means that in deriving a type by restriction, any contained type definitions must themselves be explicitly derived by restriction from the corresponding type definitions in the base definition, or be one of the member types of a corresponding union.

You can solve this if you make the type for AdultAbsoluteValue from the derived type derived from the type of AdultAbsoluteValue from the base type as below:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">

<xs:complexType name="AdultAbsoluteValueType">
<xs:attribute name="TotalDuration" type="xs:short" use="optional"/>
<xs:attribute name="NightsOfStay" type="xs:short" use="optional"/>
<xs:attribute name="Amount" type="xs:positiveInteger" use="optional"/>
</xs:complexType>

<xs:complexType name="AUPriceType">
<xs:sequence>
<xs:element name="Carrier" minOccurs="0">
<xs:complexType>
<xs:attribute name="Code" type="xs:string" use="optional"/>
<xs:attribute name="Original" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="AdultAbsoluteValue" maxOccurs="unbounded" type="AdultAbsoluteValueType"/>
</xs:sequence>
<xs:attribute name="SeasonChar" type="xs:string" use="optional"/>
<xs:attribute name="SeasonCharRef" type="xs:string" use="optional"/>
</xs:complexType>
<xs:complexType name="PricesType">
<xs:sequence>
<xs:element name="Price" maxOccurs="unbounded">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="AUPriceType">
<xs:sequence>
<xs:element name="Carrier" minOccurs="0" maxOccurs="0">
<xs:complexType>
<xs:attribute name="Code" type="xs:string" use="optional"/>
<xs:attribute name="Original" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="AdultAbsoluteValue" maxOccurs="unbounded">
<xs:complexType>
<xs:complexContent>
<xs:restriction base="AdultAbsoluteValueType">
<xs:attribute name="TotalDuration" type="xs:short" use="prohibited"/>
<xs:attribute name="NightsOfStay" type="xs:short" use="optional"/>
<xs:attribute name="Amount" type="xs:positiveInteger" use="required"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="SeasonChar" type="xs:string" use="prohibited"/>
<xs:attribute name="SeasonCharRef" type="xs:string" use="optional"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
Best Regards,
George

Posted: Wed Jan 25, 2006 9:57 pm
by alk
Hi George,

thanks a lot for your help. This is the kind of answer I was hoping for!!!

Best regards
Alex

PS: I should really have a closer look at the specification... :wink: