XML Schema 'group' element
Definition and usage
The 'group' element is used to define a set of elements that are used within a complex type definition.
Element information
Occurrence | 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 declaration is 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.
Use this attribute only 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 a parent element. This value can be any non-negative integer. If no upper limit is set for the maximum number of occurrences, use the string "unbounded". The default value is 1.
minOccurs
Optional. Specifies the minimum number of times the group element can appear in a 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 within 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>