Use <xs:all> in XML schema's complexType?

我是研究僧i 提交于 2020-01-14 22:42:48

问题


I have the following XML complexTypes defined:

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

and:

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

However, upon validation, I get an error stating that the all model group isn't allowed within the loss complexType nor its extension propLoss definition. What is it that I'm doing wrong?

Thanks!


回答1:


A problem with propLoss is that you can't extend an all group in XML Schema (1.0). From the spec:

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.

Not sure what the problem with loss is unless it collateral damage from the propLoss error.




回答2:


Note that in XSD 1.1 all groups can be extended in the way shown here, with the meaning being that all of the children mentioned in either all-group must be present in any order. (That is, all-group 1 and all-group 2 get merged together into a single all-group with the concatenation of their children.)



来源:https://stackoverflow.com/questions/7603317/use-xsall-in-xml-schemas-complextype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!