我定义了以下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
定义中。我到底做错了什么?
谢谢!
propLoss
的一个问题是不能在XML Schema(1.0)中扩展all
组。来自规范:
注意:该规范只允许追加,不允许其他类型的追加扩展。这个决定简化了所需的应用程序处理将实例从派生类型强制转换为基类型。未来的版本可能允许更多种类的扩展,需要更复杂的转换来实现影响铸件。
不确定loss
的问题是什么,除非它从propLoss
错误附带损害。
请注意,在XSD 1.1中,all
组可以按照这里所示的方式进行扩展,这意味着all
组中提到的所有子组必须以任意顺序出现。(也就是说,所有组1和所有组2被合并成一个单独的所有组,并连接它们的子组。)