【发布时间】:2015-12-03 15:59:48
【问题描述】:
我在 XSD 文件中定义了一个 object 子类型:
<xs:complexType name="object">
<xs:sequence>
<xs:element name="state" maxOccurs="unbounded" type="xs:string"/>
</xs:sequence>
</xs:complexType>
如您所见,<state> 标记已配置为可以出现任意次数(从 1 次开始)。所以这将是一个例子,我使用定义的<object>:
<System>
<object_1>
<state>string_1</state>
<state>string_2</state>
<state>string_3</state>
<object_1>
<object_2>
<state>string_4</state>
<object_2>
...
</System>
但是,有一种特殊情况,我需要用 exactly 2 <state> elements/tags (no多也不少):
<object_n>
<state>string_n1</state>
<state>string_n2</state>
</object_n>
当我在 Schema 文件中声明它时,有没有办法扩展/修改/限制这种类型,以便清楚地知道它必须只包含两个子元素?
<xs:element type="object">
<xs:somewayToLimitChildren/>
实际上,对象子类型更复杂,因此需要将其设为子类型。
【问题讨论】:
-
maxOccurs="undefined"应该是maxOccurs="unbounded" -
你是对的,谢谢!根据 Kachna cmets 编辑