Latest web development tutorials

XML Schema group elements

XML Schema Reference Complete XML Schema Reference

Definition and Usage

group element is used to define groups of elements used in complex type definitions.

Element Information

  • Parent element: schema, choice, sequence, complexType , restriction (both simpleContent and complexContent), extension (both simpleContent and complexContent)

grammar

<group
id=ID
name=NCName
ref=QName
maxOccurs=nonNegativeInteger|unbounded
minOccurs=nonNegativeInteger
any attributes
>

(annotation?,(all|choice|sequence)?)

</group>

(? Sign declares that the element in the group, this element can occur zero or one time.)

属性 描述
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 命名空间的任何其他属性。

Example 1

The following example defines a sequence of four elements comprising group and use this group of elements in a complex type definition:

<?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 Reference Complete XML Schema Reference