0

I have an XSD which refrences another schema which have a restricted type . When I open it with liquid studio or any other similar application I got the following error

Error Invalid particle derivation by restriction - 'Derived element 'http://www.saudiedi.com/schema/trfMafSts:record' is not a valid restriction of base element 'http://www.saudiedi.com/schema/sau:record' according to Elt:Elt -- NameAndTypeOK.'.

the main schema file ( TRFMAFSTS.xsd )

<xsd:schema targetNamespace="http://www.saudiedi.com/schema/trfMafSts" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:trfSts="http://www.saudiedi.com/schema/trfMafSts" xmlns:cm="http://www.saudiedi.com/schema/common" xmlns:cmSts="http://www.saudiedi.com/schema/cmSts" xmlns:trfMafCm="http://www.saudiedi.com/schema/trfMafCm" xmlns:sau="http://www.saudiedi.com/schema/sau" elementFormDefault="qualified" attributeFormDefault="qualified">
    <xsd:import namespace="http://www.saudiedi.com/schema/common" schemaLocation="../Common/common.xsd"/>
    <xsd:import namespace="http://www.saudiedi.com/schema/sau" schemaLocation="../Common/saudiedi.xsd"/>
    <xsd:import namespace="http://www.saudiedi.com/schema/cmSts" schemaLocation="../Common/cmSts.xsd"/>
    <xsd:import namespace="http://www.saudiedi.com/schema/trfMafCm" schemaLocation="trfMafCommon.xsd"/>
    <!-- Payload implementation -->
    <xsd:complexType name="overallStatusInfoType">
        <xsd:sequence>
            <xsd:element name="status" type="trfMafCm:overallStatusType"/>
            <xsd:element name="originalMsgId" type="cm:reqMsgIdType"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="trfMafStatusInfoType">
        <xsd:sequence>
            <xsd:element name="status" type="trfMafCm:transferManifestStatusType"/>
            <xsd:element name="errorCode" type="cmSts:errorCodeType" minOccurs="0"/>
            <xsd:element name="remarks" type="cmSts:statusInfoRemarksType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="referenceSeaBLInfoType">
        <xsd:sequence>
            <xsd:element name="seaBLSeqNo" type="cm:seaBLSeqNoType"/>
            <xsd:element name="status" type="trfMafCm:referenceSeaBLStatusType"/>
            <xsd:element name="errorCode" type="cmSts:errorCodeType" minOccurs="0"/>
            <xsd:element name="remarks" type="cmSts:statusInfoRemarksType" minOccurs="0"/>
            <xsd:element name="referenceSeaBLItemInfo" type="trfSts:referenceSeaBLItemInfoType" minOccurs="0" maxOccurs="999"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="referenceSeaBLItemInfoType">
        <xsd:sequence>
            <xsd:element name="seaItemSeqNo" type="cm:itemSeqNoType"/>
            <xsd:element name="status" type="trfMafCm:referenceSeaBLItemStatusType"/>
            <xsd:element name="errorCode" type="cmSts:errorCodeType" minOccurs="0"/>
            <xsd:element name="remarks" type="cmSts:statusInfoRemarksType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="overLoadedBLItemType">
        <xsd:sequence>
            <xsd:element name="seaItemSeqNo" type="cm:itemSeqNoType"/>
            <xsd:element name="status" type="trfMafCm:overLoadedBLItemStatusType"/>
            <xsd:element name="errorCode" type="cmSts:errorCodeType" minOccurs="0"/>
            <xsd:element name="remarks" type="cmSts:statusInfoRemarksType" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="overLoadedBLItemHeaderType">
        <xsd:sequence>
            <xsd:element name="voyageNo" type="trfMafCm:voyageNoType"/>
            <xsd:element name="voyageDate" type="xsd:date"/>
            <xsd:element name="trainManifestNo" type="trfMafCm:trainMafNoType"/>
            <xsd:element name="trainManifestDate" type="xsd:date"/>
            <xsd:element name="seaMafType" type="cm:seaMafType" fixed="1"/>
            <xsd:element name="seaMafDate" type="xsd:date"/>
            <xsd:element name="seaMafNo" type="cm:seaMafNoType"/>
            <xsd:element name="seaBLSeqNo" type="cm:seaBLSeqNoType"/>
            <xsd:element name="status" type="trfMafCm:referenceSeaBLStatusType"/>
            <xsd:element name="errorCode" type="cmSts:errorCodeType" minOccurs="0"/>
            <xsd:element name="remarks" type="cmSts:statusInfoRemarksType" minOccurs="0"/>
            <xsd:element name="overLoadedBLItem" type="trfSts:overLoadedBLItemType" minOccurs="0" maxOccurs="999"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="trainSetInfoType">
        <xsd:sequence>
            <xsd:element name="trainSetInfo" type="trfMafCm:trainSetHeaderTypeSts"/>
            <xsd:element name="referenceSeaBLInfo" type="trfSts:referenceSeaBLInfoType" minOccurs="0" maxOccurs="999"/>
        </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="trfStatusType">
        <xsd:complexContent>
            <xsd:extension base="sau:abstractPayloadType">
                <xsd:sequence>
                    <xsd:element name="reference" type="trfMafCm:referenceTypeForTrfSts"/>
                    <xsd:element name="overallStatusInfo" type="trfSts:overallStatusInfoType"/>
                    <xsd:element name="trfManifestStatusInfo" type="trfSts:trfMafStatusInfoType"/>
                    <xsd:element name="trainSetStatusInfo" type="trfSts:trainSetInfoType" minOccurs="0" maxOccurs="999"/>
                    <xsd:element name="overLoadedBLItemStatusInfo" type="trfSts:overLoadedBLItemHeaderType" minOccurs="0" maxOccurs="9999"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
    <!-- SaudiEdi Framework -->
    <xsd:complexType name="saudiediTrfStsType">
        <xsd:complexContent>
            <xsd:restriction base="sau:saudiEDIType">
                <xsd:sequence>
                    <xsd:element name="record" type="sau:recordType" maxOccurs="999"/>
                </xsd:sequence>
                <xsd:attribute name="docType" use="required" fixed="MAF"/>
                <xsd:attribute name="id" type="sau:msgIDType" use="required"/>
                <xsd:attribute name="msgType" use="required" fixed="TRFSTS"/>
            </xsd:restriction>
        </xsd:complexContent>
    </xsd:complexType>
    <xsd:element name="saudiEDI" type="trfSts:saudiediTrfStsType"/>
</xsd:schema>

The ( saudiedi.xsd )

<xs:schema targetNamespace="http://www.saudiedi.com/schema/sau" elementFormDefault="qualified" attributeFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sau="http://www.saudiedi.com/schema/sau" xmlns:cm="http://www.saudiedi.com/schema/common">
    <xs:import namespace="http://www.saudiedi.com/schema/common" schemaLocation="common.xsd"/>
    <xs:complexType name="abstractPayloadType" abstract="true">
        <xs:annotation>
            <xs:documentation>abstract payload for domain teams to define</xs:documentation>
        </xs:annotation>
    </xs:complexType>

    <xs:simpleType name="msgIDType">
        <xs:restriction base="xs:string">
            <xs:pattern value="\c{1,3}\d{1,14}"/>
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="recordType">
        <xs:sequence>       
            <xs:element name="payload" type="sau:abstractPayloadType"/>
        </xs:sequence>
    </xs:complexType>

    <xs:complexType name="saudiEDIType" abstract="true" block="extension">
        <xs:annotation>
            <xs:documentation>boilerplate for saudiedi documents</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="record" type="sau:recordType" maxOccurs="999"/>
        </xs:sequence>
        <xs:attribute name="docType" use="optional"/>
        <xs:attribute name="id" type="sau:msgIDType" use="optional"/>
        <xs:attribute name="msgType" use="optional"/>       
    </xs:complexType>


</xs:schema>

I'd really appreciate any help !

Geeky Omar
  • 44
  • 9

1 Answers1

1

The rule that the error message is referring to is here: https://www.w3.org/TR/xmlschema-1/#rcase-NameAndTypeOK

Schema Component Constraint: Particle Restriction OK (Elt:Elt -- NameAndTypeOK)

For an element declaration particle to be a ·valid restriction· of another element declaration particle all of the following must be true:

1 The declarations' {name}s and {target namespace}s are the same.

2 ...

But the local element declaration 'record' in TRFMAFSTS.xsd is in a different namespace from the local element declaration in saudiedi.xsd. This is because both schemas have elementFormDefault="qualified", so local elements declared in each schema are in the target namespace of that schema.

One way to fix this would be to make the 'record' element global in TRFMAFSTS.xsd and refer to it in your complex type restriction.

Community
  • 1
  • 1
kimbert
  • 2,376
  • 1
  • 10
  • 20
  • Thanks you @kimbert for your answer . Unfortunately I have no experience working with schema files so did you mean I should remove the import of saudiedi.xsd schema and define the "Record" item at the TRFSTS.xsd ? – Geeky Omar Jun 10 '20 at 12:38
  • after reading some articles I think I figured out what you meant .. is that [screenshot](https://ibb.co/zmVn8Cy) right ? – Geeky Omar Jun 10 '20 at 12:45
  • After removing "macOcccurs" attribute I got the same error as this [screenshot](https://ibb.co/5G3x1fg) – Geeky Omar Jun 10 '20 at 12:56
  • It makes no sense to put maxOccurs on a _global_ element. The maxOccurs attribute is still required, though. You need to include it on the _reference_ to 'record' (inside the sequence). – kimbert Jun 10 '20 at 13:15
  • yes I removed it and added it to the reference but I got the same first error .. kindly check my second comment screenshot – Geeky Omar Jun 10 '20 at 14:16
  • In your second screenshot, the reference does not have a maxOccurs attribute. The base type needs to have maxOccurs="999" on the element reference. – kimbert Jun 10 '20 at 17:56
  • I did it but still have the same problem as this [screenshot](https://ibb.co/drMxFmC) – Geeky Omar Jun 10 '20 at 18:58
  • Sorry, but I cannot continue like this. The schemas and error messages are unreadable in those screenshots. I'm fairly sure that my diagnosis was correct. If you need more help, close this question and open another one with a full description of the new problem. – kimbert Jun 10 '20 at 22:44
  • Okay , I really appreciate your help I will do as you recommended – Geeky Omar Jun 10 '20 at 23:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/215704/discussion-between-geeky-omar-and-kimbert). – Geeky Omar Jun 10 '20 at 23:39