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 參考