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, follow these steps:

  1. Open your XML schema in the XML schema editor.
  2. In the Outline view, select your schema.
  3. In the Graph view, right click in the Types section and click Add Complex Type.
  4. In the Properties view, type a new name for the complex type in the Name field.
  5. Click the Browse button to select a base type for your complex type. You can either set a base type for your complex type, or you add a content model to it (which represents any data that may be contained inside an element), but you cannot do both. For more information about content models, refer to the related tasks.
  6. Select restriction or extension from the Derived by list. This specifies whether your type is derived from its base type by restriction or extension.
  7. Click the Other tab. The following optional values can be specified in this page:
    1. Select the appropriate value in the abstract list. When a complex type is declared abstract, it cannot be used in an instance document. Click true if you want the complex type to be abstract; otherwise, click false.
    2. Select the appropriate value in the block list. If you select #all, the complex type may not be replaced by any derivations. If you select extension, the complex type may not be replaced by any type derived from it by extending it. If you select restriction, the complex type may not be replaced by any type derived from it by restricting it.
    3. Select the appropriate value in the final list. If you select #all, the complex type may not be derived from at all. If you select extension, the complex type may not be derived from by extension. If you select restriction, the complex type may not be derived from by restriction.
    4. Select the appropriate value in the mixed list. If you click true, the complex type can contain mixed content (both character data and other elements). If you click false, the complex type can only contain other elements.
  8. Click the Attributes tab. You can use this page to add attributes, attribute references, attributes group references, and any attributes to your complex type.
  9. An attribute associates an attribute name with a specific type and value. To add an attribute, right-click in the Attributes page, and click Add Attribute. You can specify the following values for an attribute
    • fixed/default. Click the Browse button and select the Fixed or Default radio button and specify an appropriate value. If you select Fixed, the attribute has a fixed value, which cannot be changed. If you select Default, the attribute has a default value. When an attribute has a default value, the value of the attribute is whatever value appears as the attribute's value in an instance document.
    • form. Use this field to indicate if the appearance of this attribute in an instance of the XML schema must be qualified by a namespace.
    • name. Enter the name of the attribute.
    • type. Click the Browse button and select the type of the attribute.
    • use. This field indicates how an attribute may be used in an instance document. If you select optional, the attribute may appear once, but it does not have to. If you select required, the attribute must appear once. If you select prohibited, the attribute must not appear. Note: If you selected the Default radio button, you must select optional in this field, otherwise the default value will not be valid.
  10. An attribute reference provides a reference to a global attribute. To add an attribute reference, right-click in the Attributes page, and click Add Attribute Ref. A declaration that references a global attribute enables the referenced attribute to appear in the instance document in the context of the referencing declaration. The menu option to add an attribute reference only appears if there are global attributes defined elsewhere in the document.
    1. Select the reference, then select the global attribute you want it to reference from the ref drop down list.
  11. An attribute group reference provides a reference to an attribute group. To add an attribute group reference, right-click in the Attributes page, and click Add Attribute Group Ref.  A declaration that references an attribute group enables the referenced attribute group to appear in the instance document in the context of the referencing declaration. The menu option to add an attribute group reference only appears if there are attribute groups defined elsewhere in the document.
    1. Select the reference, then select the attribute group you want it to reference from the ref drop down list.
  12. An any element enables element content according to namespaces, and the corresponding any attribute element enables attributes to appear in elements. To add an any attribute, right-click in the Attributes page, and click Add Any Attribute. You can specify the following values for an any attribute:
    • For a namespace value, you can select ##any (this allows any well-formed XML from any namespace), ##local (this allows any well-formed XML that is not declared to be in a namespace, ##other (this allows any well-formed XML that is not from the target namespace of the type being defined) or ##targetNamespace (which is shorthand for the target namespace of the type being defined).
    • For a processContents value, you can select skip (the XML processor will not validate the attribute content at all), lax (the XML processor will validate the attribute content as much as it can), or strict (the XML processor will validate all the attribute content).
  13. 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, and the App Info page can be used to provide information for applications.

Related tasks
Adding a content model