【发布时间】:2015-09-23 14:12:17
【问题描述】:
我需要编写一个 XSD 架构。在此架构中,一些元素是已知的和强制性的,其他元素是未知的和可选的:
<father>
<childMandatory1 />
<childMandatory2 />
<childOptionnal1 />
</father>
或:(更改强制子订单)
<father>
<childMandatory2 />
<childMandatory1 />
</father>
我知道强制的孩子(但不知道他们的顺序)。但我不知道是否会有任何可选的 child(ren)(如果有,他们的名字)。
我尝试使用“xs:all”,但“xs:all”不允许使用“any”:
<xs:element name="father">
<xs:complexType>
<xs:all>
<xs:element ref="childMandatory1" />
<xs:element ref="childMandatory2" />
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax"/>
<!-- error here ! -->
</xs:all>
</xs:complexType>
</xs:element>
我尝试了序列,但我应该知道元素的顺序。 (我没有)
我尝试了选择,但选择不能与任何和一些强制性元素一起使用。 (并且我想确保强制元素存在)
【问题讨论】:
-
也许你应该在
xs:choice里面使用xs:any -
@AlexanderPetrov,这也将违反UPA principle。