element group XML Schema

definisi dan penggunaan

element group digunakan untuk mensifatkan kumpulan element yang digunakan dalam definisi jenis kompleks.

maklumat element

bilangan penampilan tanpa batasan
element utama schema、choice、sequence、complexType、restriction (complexContent)、extension (complexContent)
kandungan 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>