xml - 使用 <xs :all> in XML schema's complexType?

标签 xml xsd schema complextype

我定义了以下 XML complexType:

<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 及其扩展中不允许使用 all 模型组propLoss 定义。我做错了什么?

谢谢!

最佳答案

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

Note: This specification allows only appending, and not other kinds of extensions. This decision simplifies application processing required to cast instances from derived to base type. Future versions may allow more kinds of extension, requiring more complex transformations to effect casting.

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

关于xml - 使用 <xs :all> in XML schema's complexType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7603317/

相关文章:

XML Schema - 依赖于可选属性存在的子元素

xml - 获取 xsi :type with xpath 的值

node.js - 如何处理 Mongoose 中的 ENUM 值?

c# - LINQ - (x, i) 做什么?

c# - 以编程方式从 XML 模式生成测试 XML

xml - 在 XML 中表示空属性值的标准方法?

sql - 使用一对多与多对多关系的数据库设计优势

java - char '0x8' 这是什么字符?

Maven Jaxb2 xjc 插件错误没有找到模式

mysql - 数据库设计: same table - mixed data VS several tables - same schema