0

我有一个 XSD,它引用了另一个具有受限类型的模式。当我用液体工作室或任何其他类似的应用程序打开它时,我收到以下错误

错误通过限制进行的无效粒子派生 - '派生元素' http://www.saudiedi.com/schema/trfMafSts:record '不是基本元素的有效限制' http://www.saudiedi.com/schema/sau:记录'根据 Elt:Elt -- NameAndTypeOK.'。

主模式文件 (TRMFMAFSTS.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>

(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>

我真的很感激任何帮助!

4

1 回答 1

1

错误消息所指的规则在这里:https ://www.w3.org/TR/xmlschema-1/#rcase-NameAndTypeOK

Schema 组件约束:粒子限制 OK (Elt:Elt -- NameAndTypeOK)

要使一个元素声明粒子成为另一个元素声明粒子的“有效限制”,以下所有条件都必须为真:

1 声明的 {name} 和 {target namespace} 相同。

2 ...

但是TRFMAFSTS.xsd 中的本地元素声明“记录”与 saudiedi.xsd 中的本地元素声明位于不同的命名空间中。这是因为两个模式都有 elementFormDefault="qualified",所以在每个模式中声明的本地元素都在该模式的目标命名空间中。

解决此问题的一种方法是使 TRFMAFSTS.xsd 中的“记录”元素成为全局元素,并在您的复杂类型限制中引用它。

于 2020-06-09T22:27:56.983 回答