# Adding complex types

A complex type allows elements in its content and can carry attributes. Complex types can be used to help determine the appropriate content for any instance documents generated from or associated with your XML schema.

You can add as many complex types as you want to an XML schema.

The following instructions were written for the Resource perspective, but they will also work in many other perspectives.

To add a complex type to an XML schema, complete the following steps:

1. Open your XML schema in the XML schema editor.
2. Right-click the Types category in the Design view, click Add Complex Type and type the name for the complex type. If you need to change the name later, you can edit it in the General tab of the Properties view.
3. To set a base type for the complex type, right-click the type in the Design view and click Set Base Type. You can either set a base type for your complex type, or you can add a content model to it (which represents any data that can be contained inside an element), but you cannot do both. For more information about content models, see Adding content models.
4. Your new type can be derived from its base type either by extension or restriction. By default, the derivation is set to extension. To change how the type is derived, click the General tab in the Properties view and select restriction or extension from the Inherited By list.
5. To add attributes to your complex type, in the Design view, right-click your complex type and select Add Attribute. An attribute associates an attribute name with a specific type and value.
   1. To set the name of the attribute, in the Design view, double-click the name of the attribute and type the name.
   2. To set the type of the attribute, in the Design view, double-click the attribute type and then select the new type from the list.
   For information about adding attributes, attribute references, and `any` attributes, see Adding attribute groups.
6. You can further define your complex type in the Properties view:
   1. Click the Documentation tab if you want to provide any information about this complex type. The Documentation page is used for human readable material, such as a description.
   2. Click the Extensions tab if you want to add application information elements to your annotations of schema components. The Extensions page allows you to specify the schema and add XML content to your annotations.

Related tasks
Adding content models