XML Schema group 元素
定義和用法
group 元素用于定義在復(fù)雜類(lèi)型定義中使用的元素組。
元素信息
出現(xiàn)次數(shù) | 無(wú)限制 |
父元素 | schema、choice、sequence、complexType、restriction (complexContent)、extension (complexContent) |
內(nèi)容 | annotation、all、choice、sequence |
語(yǔ)法
<group id=ID name=NCName ref=QName maxOccurs=nonNegativeInteger|unbounded minOccurs=nonNegativeInteger any attributes > annotation?,(all|choice|sequence)?) </group>
(? 符號(hào)聲明在 group 元素中,該元素可出現(xiàn)零次或一次。)
屬性
id
可選。規(guī)定該元素的唯一的 ID。
name
可選。規(guī)定組的名稱(chēng)。該名稱(chēng)必須是在 XML 命名空間規(guī)范中定義的無(wú)冒號(hào)名稱(chēng) (NCName)。
僅當(dāng) schema 元素是該 group 元素的父元素時(shí)才使用該屬性。在此情況下,group 是由 complexType、choice 和 sequence 元素使用的模型組。
name 屬性和 ref 屬性不能同時(shí)出現(xiàn)。
ref
可選。引用另一個(gè)組的名稱(chēng)。ref 值必須是 QName。 ref 可以包含命名空間前綴。
name 屬性和 ref 屬性不能同時(shí)出現(xiàn)。
maxOccurs
可選。規(guī)定 group 元素可在父元素中出現(xiàn)的最大次數(shù)。該值可以是大于或等于零的整數(shù)。若不想對(duì)最大次數(shù)設(shè)置任何限制,請(qǐng)使用字符串 "unbounded"。默認(rèn)值為 1。
minOccurs
可選。規(guī)定 group 元素可在父元素中出現(xiàn)的最小次數(shù)。該值可以是大于或等于零的整數(shù)。默認(rèn)值為 1。
any attributes
可選。規(guī)定帶有 non-schema 命名空間的任何其他屬性。
實(shí)例
例子 1
下面的例子定義一個(gè)包含四個(gè)元素的序列的組,并在一個(gè)復(fù)雜類(lèi)型定義中使用了這個(gè) 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>