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. Right-click the Types category in the Design view, and click Add Complex Type.
  3. In the Properties view, type a new name for the complex type in the Name field.
  4. Click Browse Browse icon to select a base type for your complex 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, refer to the related tasks.
  5. Select restriction or extension from the Inherited by list. This specifies whether your type is derived from its base type by restriction or extension.
  6. The Design view will display the attributes within the complex type. You can also use this view to add attributes to your complex type. An attribute associates an attribute name with a specific type and value.
    • To add an attribute, in the Design view, right click your complex type and select Add Attribute.
      • name. In the Design view, click the name of the attribute to make a change.
      • type. In the Design view, click the type of the attribute to make a change. The drop-down menu provides commonly used types. For more options, simply select Browse from the menu.
  7. An attribute reference provides a reference to a global attribute. To add an attribute reference, in the Design view, right-click the complex type containing the element, 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. Select the reference, then select the attribute group you want it to reference in the Properties view, from the Ref menu.
  8. An attribute group reference provides a reference to an attribute group. To add an attribute group reference, in the Design view, right-click the complex type containing the element, 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. Select the reference, then select the attribute group you want it to reference in the Properties view, from the Ref menu.
  9. 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 complex type header, 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.
      • ##targetNamespace . This 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.
      • strict. The XML processor will validate all the attribute content.
  10. 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.
  11. 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