A new <complexType> can be defined by restricting an existing <complexType>. A restricted complexType must re-declare all of the contained elements that it wants to make available, no new elements can be added. Child elements that are declared may be further restricted in by changing the cardinality, type, facets or fixed values. Conversely any attributes in the base complexType are deemed to be available in the derived type by default, if an attribute needs removing from the restricted type then it must be declared and marked as use=prohibited.
ComplexTypes can only be defined at global level (as a child of the <schema>).
|The complex type that restricts another complexType is given the icon .|
A <complexType> can only be added to the <schema> object. This can be done using the right click context menu Add Child->Complex Type.
The ComplexType is automatically turned into an extension when its type is set to another complexTye (in our example Employee), to make it a restriction set the property 'Derived By = Restriction'.
Name - The name the complex type will be referred to as. This must be unique, and its a good standard to postfix it with 'Type').
Type - (optional) It is possible to create a new complex type based on an existing simple or complex type. If you specify an existing type then there are 2 ways that the 'base' type can be interpreted determined by the 'Derived By' property.
Derived By - Only available when the base type is specified. If this is Extension , then the complexType takes all the properties of the 'Type' (elements/attributes etc), and allows a new compositor (<all>, <choice>, <sequence>) and <attribute>'s to be added to it. If the value is Restriction, then the complexType can ONLY contain the elements and attributes defined in the 'Type'. You can not add in elements and attributes that are not defined in the base type.
Abstract - If this is true then it means that the complexType can not be used on its own, it must be extended or restricted before it can be used (See 'Derived By' and 'Type' properties).
Block - Indicates that the type can not be substituted, extended or restricted - see 'Derived By' Property and Substitution Groups on <element>.
Final - .
Id - A user defined ID to uniquely identify the entity within the schema.
Mixed - Indicates if the XML element described by this complexType may contain text interspersed between its child elements (like HTML). It is recommended that is is false, as it makes processing the resulting XML documents more difficult, but it is sometimes necessary to use this.
The following XSD code
|ComplexType Example||Copy Code|
<xs:complexType name="Employee"> <xs:sequence> <xs:element name="Name" type="xs:string" /> <xs:element name="DateOfBirth" type="xs:date" /> <xs:element name="Salary" type="xs:int" minOccurs="0" /> </xs:sequence> </xs:complexType> <xs:complexType name="Intern"> <xs:complexContent> <xs:restriction base="Employee"> <xs:sequence> <xs:element name="Name" type="xs:string" /> <xs:element name="DateOfBirth" type="xs:date" /> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType>
Restricted Node Notation
When an item is restricted a template is produced showing all the items (elements, attributes, etc) that have been taken from the base type. Items that have a line through them are not allowed within the resulting type.
Grayed out items are empty placeholders taken from items defined within the base types, clicking the ( icon) will cause its definition to be included into the type, this can then be further restricted using facets, changing the type etc.
Clicking the ( icon) on a restricted child item will cause its definition to be removed from the restricted type.
A line through an item means that it is not available within the restricted type.
By default attributes from the base type are available in the restricted type, to remove them, define them in the restricted type and set 'use=prohibited'.
By default elements from the base type are not part of the restricted type, to include them, then must be defined within the restricted type.
Properties that apply to a type are shown inline at the bottom of the items container.
Values that are inherited from the base types are shown in brackets, values specifically set against the item are shown without brackets.
If a facet is not valid for a given type (typically because of its data type), then its value is shown in red.
|Inline properties can be disabled in the Options.|