【问题标题】:Use <xs:all> in XML schema's complexType?在 XML 模式的 complexType 中使用 <xs:all>?
【发布时间】:2011-11-28 00:48:45
【问题描述】:

我定义了以下 XML complexTypes:

<xs:complexType name="loss">
    <xs:all>
        <xs:element name="lossCause" type="xs:string"/>
        <xs:element name="lossDate" type="xs:dateTime"/>
        <xs:element name="lossDescription" type="xs:string"/>
        <xs:element name="lossLocation" type="address" minOccurs="0"/>
        <xs:element name="lossTime" type="xs:string" minOccurs="0"/>
        <xs:element name="officials" minOccurs="0">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="official" type="official" minOccurs="0" maxOccurs="unbounded"/>
                </xs:sequence>
            </xs:complexType>
        </xs:element>
    </xs:all>
    <xs:attribute name="incidentOnly" type="xs:boolean" use="required"/>
    <xs:attribute name="lawsuit" type="xs:boolean" use="required"/>
</xs:complexType>

和:

<xs:complexType name="propLoss">
    <xs:complexContent>
        <xs:extension base="loss">
            <xs:all>
                <xs:element name="damageDescription" type="xs:string"/>
                <xs:element name="property" type="property"/>
                <xs:element name="responsibleParty" type="contact" minOccurs="0"/>
            </xs:all>
            <xs:attribute name="businessOperational" type="xs:boolean" use="required"/>
            <xs:attribute name="propertyLivable" type="xs:boolean" use="required"/>
            <xs:attribute name="weatherRelated" type="xs:boolean" use="required"/>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>

但是,在验证后,我收到一条错误消息,指出 loss complexType 或其扩展名 propLoss 定义中不允许使用 all 模型组。我做错了什么?

谢谢!

【问题讨论】:

    标签: xml xsd schema complextype


    【解决方案1】:

    propLoss 的一个问题是您不能在 XML Schema (1.0) 中扩展 all 组。来自规范:

    注意:本规范只允许追加,不允许其他类型的 扩展名。这一决定简化了所需的申请处理 将实例从派生类型转换为基类型。未来的版本可能允许 更多种类的扩展,需要更复杂的转换 效果投射。

    不确定loss 的问题是什么,除非它是由propLoss 错误造成的附带损害。

    【讨论】:

    • 感谢您的澄清。您不会碰巧对此有任何解决方法的想法吗?
    • 由于“所有”组项目最多只能出现一次,因此一个论点是:如果顺序在您的数据模型中不重要,只需为您的交换格式选择任意顺序。也就是说,将每个“全部”转换为“序列”。
    【解决方案2】:

    请注意,在 XSD 1.1 中,all 组可以按照此处所示的方式进行扩展,其含义是 all-group 中提到的所有子项必须以任意顺序出现。 (也就是说,all-group 1 和 all-group 2 合并成一个 all-group 及其子级。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-15
      • 2011-03-22
      • 2011-09-29
      • 2012-02-24
      • 1970-01-01
      • 2019-01-13
      • 1970-01-01
      相关资源
      最近更新 更多