schema validation errors + xs:restriction

This should cover W3C XML Schema, Relax NG and DTD related problems.
diman
Posts: 2
Joined: Thu Apr 28, 2005 6:54 pm

schema validation errors + xs:restriction

Post by diman »

hi all,
I have the error (E derivation-ok-restriction.5.4.2: Error for type 'MyErpAddress'. The particle of the type is not a valid restriction of the particle of the base) when trying to validate the info.xsd
Could someone please tell me what I did wrong? Must the restricted have the same namespace as the base?

-------------------------------------------------------------------------------
components.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="components" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:compt="components" targetNamespace="components" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:complexType name="ErpAddress" >
<xs:sequence>
<xs:element name="streetNumber" type="xs:string" minOccurs="0"/>
<xs:element name="streetName" type="xs:string" minOccurs="0"/>
<xs:element name="streetSuffix" type="xs:string" minOccurs="0"/>
<xs:element name="streetPrefix" type="xs:string" minOccurs="0"/>
<xs:element name="streetType" type="xs:string" minOccurs="0"/>
<xs:element name="suiteNumber" type="xs:string" minOccurs="0"/>
<xs:element name="city" type="xs:string" minOccurs="0"/>
<xs:element name="country" type="xs:string" minOccurs="0"/>
<xs:element name="postalCode" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>

------------------------------------------------------------------------------
info.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="info" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:compt="components" targetNamespace="info" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="components" schemaLocation="components.xsd"/>
<xs:complexType name="MyErpAddress">
<xs:complexContent>
<xs:restriction base="compt:ErpAddress">
<xs:sequence>
<xs:element name="streetNumber" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="streetName" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="postalCode" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:length value="5"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Diman,

When you make a derivation by restriction you need to have an order preserving mapping between the content of the derived type and the content of the base type. If you have local elements (that is they are defined locally and not as a top level element) in the base type you can restrict that type only if those elements are emptyable and you remove them in the restriction. Two local declaration although have the same name they are not the same particle. The error reported by oXygen points you to:
http://www.w3.org/TR/xmlschema-1/#rcase-Recurse
clause 2
and you can follow that to
http://www.w3.org/TR/xmlschema-1/#cd-model-restriction
for more details.

Best Regards,
George
diman
Posts: 2
Joined: Thu Apr 28, 2005 6:54 pm

Post by diman »

George,

Thank you for your reply! But putting all type descriptions into the same file makes the stuff working properly. I'm still don't really understand the difference.

Diman
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Diman,

The key is elementFormDefault="qualified". That brings the local elements in the target namespace which is different for the two schemas. If you change that to elementFormDefault="unqualified", that is placing the local elements in no namespace then the schemas will be both reported valid.
In the case you move everything in one document then you have the same target namespace so again the schema is valid.

Best Regards,
George
Post Reply