XML Schema attributeGroup Element

Definition and Usage

The attributeGroup element is used to combine attribute declarations so that these declarations can be merged into complex types as a group.

Element Information

Occurrence Unrestricted
Parent Element attributeGroup, complexType, schema, restriction (simpleContent), extension (simpleContent), restriction (complexContent), extension (complexContent)
Content annotation, attribute, attributeGroup, anyAttribute

Syntax

<attributeGroup
id=ID
name=NCName
ref=QName
any attributes
>
(annotation?),((attribute|attributeGroup)*,anyAttribute?))
</attributeGroup>

(? symbol is declared in the attributeGroup element, the element can appear zero or one times, * symbol is declared, the element can appear zero or more times.)

Attribute Description
id Optional. Specifies the unique ID of the element.
name Optional. Specifies the name of the attribute group. The name and ref attributes cannot appear together.
ref Optional. Specifies a reference to the specified attribute group. The name and ref attributes cannot appear together.
any attributes Optional. Specifies any other attributes with a non-schema namespace.

Instance

<xs:attributeGroup name="personattr">
  <xs:attribute name="attr1" type="string"/>
  <xs:attribute name="attr2" type="integer"/>
</xs:attributeGroup>
<xs:complexType name="person">
  <xs:attributeGroup ref="personattr"/>
</xs:complexType>

The above example defines an attribute group named "personattr" that is used in the complex type named "person".