schema validation errors + xs:restriction
This should cover W3C XML Schema, Relax NG and DTD related problems.
schema validation errors + xs:restriction
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>
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>
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
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
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
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
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service