XML Schema group 元素
完整 XML Schema 參考手冊
定義和用法
group 元素用于定義在復雜類型定義中使用的元素組。
元素信息
- 父元素: schema, choice, sequence, complexType, restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent)
語法
<group
id=ID
name=NCName
ref=QName
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>
(annotation?,(all|choice|sequence)?)
</group>
(? 符號聲明在 group 元素中,該元素可出現零次或一次。)
屬性 | 描述 |
id | 可選。規定該元素的唯一的 ID。 |
name | 可選。規定組的名稱。該名稱必須是在 XML 命名空間規范中定義的無冒號名稱 (NCName)。 僅當 schema 元素是該 group 元素的父元素時才使用該屬性。在此情況下,group 是由 complexType、choice 和 sequence 元素使用的模型組。 name 屬性和 ref 屬性不能同時出現。 |
ref | 可選。引用另一個組的名稱。ref 值必須是 QName。 ref 可以包含命名空間前綴。 name 屬性和 ref 屬性不能同時出現。 |
maxOccurs | 可選。規定 group 元素可在父元素中出現的最大次數。該值可以是大于或等于零的整數。若不想對最大次數設置任何限制,請使用字符串 "unbounded"。默認值為 1。 |
minOccurs | 可選。規定 group 元素可在父元素中出現的最小次數。該值可以是大于或等于零的整數。默認值為 1。 |
any attributes | 可選。規定帶有 non-schema 命名空間的任何其他屬性。 |
實例 1
下面的例子定義一個包含四個元素的序列的組,并在一個復雜類型定義中使用了這個 group 元素:
<?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 參考手冊