用xsd:any或xsd:sequence混合xsd:choice?
问题描述:
我有以下两个(不变),XML与相同命名空间的文件,我需要创建一个XSD:用xsd:any或xsd:sequence混合xsd:choice?
伪XML例子#1:
<Project>
<ProjectInformation/>
<HistoryEntry/>
<UserFiles/>
</Project>
伪XML例子# 2:
<Project>
<Installations/>
</Project>
没有HistoryEntry
和UserFiles
元素,我会用xsd:choice
为ProjectInformation
和Installations
。但是如何将HistoryEntry
和UserFiles
元素带入游戏?
是否有标准的XSD机制允许这样做?
答
无序被高估。只需使用xs:sequence
而不是xs:any
避免XSD 1.0独特的颗粒归属违规:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Project">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="ProjectInformation"/>
<xs:element name="HistoryEntry"/>
<xs:element name="UserFiles"/>
</xs:sequence>
<xs:element name="Installations"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
谢谢,我不知道我可以在选择混合顺序和元素。现在对我的作品。 – Alex