【问题标题】:What is the problem with XSD base type restrictionXSD基本类型限制有什么问题
【发布时间】:2020-06-09 14:46:47
【问题描述】:

我有一个 XSD,它引用了另一个具有受限类型的模式。当我使用 Liquid Studio 或任何其他类似应用程序打开它时,出现以下错误

根据 Elt:Elt -- NameAndTypeOK,'Derived element'http://www.saudiedi.com/schema/trfMafSts:record' 不是对基本元素'http://www.saudiedi.com/schema/sau:record' 的有效限制。

主架构文件(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>

非常感谢任何帮助!

【问题讨论】:

    标签: xml xsd xsd-validation xmlschema


    【解决方案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 中的“记录”元素成为全局元素,并在您的复杂类型限制中引用它。

    【讨论】:

    • 感谢@kimbert 的回答。不幸的是,我没有使用架构文件的经验,所以您的意思是我应该删除 saudiedi.xsd 架构的导入并在 TRFSTS.xsd 中定义“记录”项?
    • 在阅读了一些文章后,我想我明白你的意思了.. 是screenshot 对吗?
    • 删除“macOcccurs”属性后,我得到了与screenshot相同的错误
    • 将 maxOccurs 放在 global 元素上是没有意义的。不过,maxOccurs 属性仍然是必需的。您需要将其包含在 reference 中以“记录”(在序列内)。
    • 是的,我将其删除并将其添加到参考中,但我得到了相同的第一个错误.. 请检查我的第二个评论屏幕截图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-07
    • 2015-07-11
    相关资源
    最近更新 更多