XML Schema group 元素
❮ 完整的 XML Schema 参考
定义和用法
group 元素用于在复杂类型定义中定义一组要使用的元素。
元素信息
- 父元素: schema, choice, sequence, complexType, restriction (simpleContent 和 complexContent), extension (simpleContent 和 complexContent)
语法
<group
id=ID
name=NCName
ref=QName
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
任何属性
>
(annotation?,(all|choice|sequence)?)
</group>
(? 符号表示元素在 group 元素内可以出现零次或一次)
Attribute | 描述 |
---|---|
id | 可选。指定元素的唯一 ID |
name | 可选。为组指定一个名称。仅当 schema 元素是此 group 元素的父元素时才使用此属性。Name 和 ref 属性不能同时存在。 |
ref | 可选。引用另一个组的名称。Name 和 ref 属性不能同时存在。 |
maxOccurs | 可选。指定 group 元素在父元素中可以出现的最多次数。该值可以是任何大于等于 0 的数字,如果想设置无最大限制,请使用“unbounded”值。默认值为 1。 |
minOccurs | 可选。指定 group 元素在父元素中可以出现的最小次数。该值可以是任何大于等于 0 的数字。默认值为 1。 |
任何属性 | 可选。指定任何其他非 schema 命名空间的属性 |
示例 1
以下示例定义了一个包含四个元素的序列的组,并在复杂类型定义中使用该组元素。
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:group name="custGroup">
<xs:sequence>
<xs:element name="customer" type="xs:string"/>
<xs:element name="orderdetails" type="xs:string"/>
<xs:element name="billto" type="xs:string"/>
<xs:element name="shipto" type="xs:string"/>
</xs:sequence>
</xs:group>
<xs:element name="order" type="ordertype"/>
<xs:complexType name="ordertype">
<xs:group ref="custGroup"/>
<xs:attribute name="status" type="xs:string"/>
</xs:complexType>
</xs:schema>
❮ 完整的 XML Schema 参考