【发布时间】:2019-09-10 23:00:28
【问题描述】:
我正在为我们的(旧)XML 输出编写一个模式,并且遇到了一个元素可能包含一些子元素的问题。我在架构中使用了“xs:all minOccurs="0",但是当我针对 XML 进行验证时,它需要每个子元素至少有一个实例。
<xs:element name="Project">
<xs:complexType>
<xs:all minOccurs="0" maxOccurs="1">
<xs:element ref="lit:ProductPool" minOccurs="1"/>
<xs:element ref="lit:ProjectDefaults"/>
<xs:element ref="lit:TaskInfo"/>
</xs:all>
<xs:attribute name="Name" type="lit:TextType_2010"/>
... a bunch more
然后,当我使用它来验证一些只有“ProductPool”子元素的 XML 时,验证器会抱怨其他 2 个缺少并且是必需的。
Reason: The following elements are expected after this location (see below)
'lit:TaskInfo'
'lit:ProjectDefaults'
Error location: MetrixXML / Project
Details
cvc-complex-type.1.4: The content for element <Project> is incomplete.
cvc-type.3.2: Element <Project> is not valid with respect to type definition '{anonymous}'.
cvc-elt.5.2.1: The element <Project> is not valid with respect to the actual type definition '{anonymous}'.```
【问题讨论】:
标签: xsd xsd-validation