在XML模式的complexType中使用<xs:all>?</xs:all>

时间:2011-09-29 20:56:47

标签: 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>

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

谢谢!

2 个答案:

答案 0 :(得分:4)

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

  

注意:此规范仅允许附加,而不允许其他类型   扩展。此决定简化了所需的应用程序处理   将实例从派生类型转换为基类型。未来版本可能允许   更多种类的扩展,需要更复杂的转换   效果铸造。

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

答案 1 :(得分:3)

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