XML Schema group element
Definition and usage
The group element is used to define a group of elements used in complex type definitions.
Element information
Occurrence frequency | Unrestricted |
Parent element | schema, choice, sequence, complexType, restriction (complexContent), extension (complexContent) |
Content | annotation, all, choice, sequence |
Syntax
<group id=ID name=NCName ref=QName maxOccurs=nonNegativeInteger|unbounded minOccurs=nonNegativeInteger any attributes > annotation?,(all|choice|sequence)?) </group>
(The ? symbol declares in the group element, which can appear zero or one time.)
Attributes
id
Optional. Specifies a unique ID for the element.
name
Optional. Specifies the name of the group. This name must be a non-colon name (NCName) defined in the XML namespace specification.
This attribute should only be used when the schema element is the parent element of the group element. In this case, the group is the model group used by the complexType, choice, and sequence elements.
The name attribute and the ref attribute cannot appear at the same time.
ref
Optional. References the name of another group. The ref value must be a QName. ref can include a namespace prefix.
The name attribute and the ref attribute cannot appear at the same time.
maxOccurs
Optional. Specifies the maximum number of times the group element can appear in the parent element. This value can be any non-negative integer. If you do not want to set any limit on the maximum number of occurrences, please use the string "unbounded". The default value is 1.
minOccurs
Optional. Specifies the minimum number of times the group element can appear in the parent element. This value can be any non-negative integer. The default value is 1.
any attributes
Optional. Specifies any other attributes with a non-schema namespace.
Instance
Example 1
The following example defines a group containing a sequence of four elements and uses this group element 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>