<xsd:group> Element
Groups a set of element declarations so that they can be incorporated as a group into complex type definitions.
<group
name= NCName
id = ID
maxOccurs = (nonNegativeInteger | unbounded) : 1
minOccurs = nonNegativeInteger : 1
name = NCName
ref = QName
{any attributes with non-schema Namespace}...>
Content: (annotation?, (all | choice | sequence))
</group>
Attributes
name
The name of the group. The name must be a no-colon-name (NCName) as defined in the XML Namespaces specification.This attribute is used only when the schema element is the parent of this group element. In this case, the group is a model group to be used by complexType, choice, and sequence elements.
Optional.
id
The ID of this element. The id value must be of type ID and be unique within the document containing this element.Optional.
maxOccurs
The maximum number of times the element can occur within the containing element. The value can be an integer greater than or equal to zero. To set no limit on the maximum number, use the string "unbounded".Limited when the group is not a child of the schema element.
Optional.
minOccurs
The minimum number of times the element can occur within the containing element. The value can be an integer greater than or equal to zero. To specify that this element is optional, set this attribute to zero.Limited when the group is not a child of the schema element.
Optional.
name
The name of the element. The name must be a no-colon-name (NCName) as defined in the XML Namespaces specification. Name and ref attributes cannot both be present.Required if the containing element is the schema element.
Optional.
ref
The name of a group declared in this schema (or another schema indicated by the specified namespace). The ref value must be a QName. The ref can include a namespace prefix.If the ref attribute is present, id, minOccurs, and maxOccurs may be present. Ref and name are mutually exclusive.
To declare a group using an existing group definition, use the ref attribute to specify the existing group definition.
<xs:group ref="globalGroup"/>
Optional.
Element Information
Number of occurrences |
Unlimited |
Parent elements |
schema, choice, sequence, complexType, restriction (complexContent), extension (complexContent) |
Contents |
Remarks
Any one of the following elements can be a child of the group element.
choice |
Permits one and only one of the elements contained in the group. |
sequence |
Requires the elements in the group to appear in the specified sequence. |
all |
Allows the elements in the group to appear (or not appear) in any order in the containing element. |
The minOccurs and maxOccurs attributes have the default value 1. A group with neither attribute must appear once and only once in the containing element.
Example
The following example defines a group containing a sequence of three elements and uses the group element in a complex type definition.
<xs:element name="thing1" type="xs:string"/>
<xs:element name="thing2" type="xs:string"/>
<xs:element name="thing3" type="xs:string"/>
<xs:attribute name="myAttribute" type="xs:decimal"/>
<xs:group name="myGroupOfThings">
<xs:sequence>
<xs:element ref="thing1"/>
<xs:element ref="thing2"/>
<xs:element ref="thing3"/>
</xs:sequence>
</xs:group>
<xs:complexType name="myComplexType">
<xs:group ref="myGroupOfThings"/>
<xs:attribute ref="myAttribute"/>
</xs:complexType>
Other Resources
For more information see the W3C XML Schema Part 1: Structures Recommendation at www.w3.org/TR/2001/REC-xmlschema-1-20010502/\#element-all.