【发布时间】:2010-07-20 22:00:02
【问题描述】:
我想创建一个包含以下内容的 XML 模式:
<xs:complexType name="Record">
<!--required elements-->
<xs:element name="RecordTag" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="RecordSize" type="xs:string" minOccurs="1" maxOccurs="1" />
<xs:element name="RecordSection" type="xs:string" minOccurs="1" maxOccurs="1" />
<!--optional elements-->
<xs:element name="RecordName" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="RecordType" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="RecordValue" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="RecordDefault" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="RecordComment" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="RecordURL" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="Condition" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="Master" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="RecordCurrent" type="xs:string" minOccurs="0" maxOccurs="1" />
<xs:element name="RecordId" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:complexType>
从 cmets 可以看出,我希望前三个元素是必需的,其余是可选的。架构应该允许元素以任何顺序出现。
现在,如果我使用<xs:sequence> 指示符,则会强制执行订单,这是我不想要的。
如果我使用<xs:all> 指示符,那么架构要求所有元素都出现,即使minOccurs 值设置为0。
还有其他指标可以用来完成我的任务吗?
谢谢!
【问题讨论】:
-
通常
应该满足您的需求。 CF:w3schools.com/schema/el_all.asp -
如果我使用
,我该如何让它仍然需要前三个元素? -
@Blue:你有没有得到答案?还是这不可能?
-
我认为我没有得到答案(至少在这里),但如果我记得我想出了如何做我需要的事情。不幸的是,我不再在那家公司工作,所以我无法查找我的解决方案的来源!
-
@Blue 你没有使用 use="required" 属性吗?