XML Schema group 元素
定義和用法
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>
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>
<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參考手冊