xs:group

This element is used in two different contexts:

  • As a model group definition in xs:schema:

    Purpose

    In this context, the element defines a named model group to be reused later on in the schema definition. A named model group is a group of elements belonging together that is given a common name for later reference.

    See the section Model Group Definition Schema Component in W3C XML Schema - Part 1.

    Parent element xs:schema
    Child elements xs:all, xs:choice, xs:element, xs:sequence
    Attributes name
    Attributes
    Name Type Description
    name xs:NCName The name attribute is mandatory. Its value is the name that identifies the group of elements.
  • As a model group reference in xs:choice, xs:sequence or xs:complexType:

    Purpose This element references a predefined model group. This leads to the insertion of the whole model group at the current location in the schema.
    Parent element xs:choice, xs:complexType, xs:extension, xs:sequence
    Child elements None
    Attributes ref, minOccurs, maxOccurs
    Attributes
    Name Type Description
    ref xs:QName

    A global group can be referenced in other declarations in the same schema using the ref attribute of the xs:group element. The value of the ref attribute must refer to a global group. If you specify a ref attribute, you may not specify a name attribute on that group declaration.

    This attribute is mandatory.

    minOccurs xs:nonNegativeInteger This attribute is optional. It specifies the minimum number of occurrences of the group.
    maxOccurs xs:string This attribute is optional. It specifies the maximum number of occurrences of the group.

    Example

    <xs:group name="address">
      <xs:element name="firstname" type="xs:string" />
      <xs:element name="lastname" type="xs:string" />
      <xs:element name="street" type="xs:string" />
      <xs:element name="town" type="xs:string" />
      <xs:element name="zip" type="xs:string" />
    </xs:group>
    <xs:element name="letter">
      <xs:complexType>
        <xs:sequence>
          <xs:element name="sender">
            <xs:complexType>
              <xs:group ref="address" />
            </xs:complexType>
          </xs:element>
          <xs:element name="addressee">
            <xs:complexType>
              <xs:group ref="address" />
            </xs:complexType>
          </xs:element>
          <xs:element name="text" />
        </xs:sequence>
      </xs:complexType>
    </xs:element>