Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

Restricting Complex Types

The restriction element provides functionality for deriving a complex type that restricts a base complex type. For simple content, these restrictions might only specify constraining facets that apply to simple content or to the attribute types. For complex content, the restriction permits altering attributes of nested element types or attribute types.

The next element describes a restriction of the partOptionType complex type presented in the all element type section. Specifically, certain parts do not require a size:

<xsd:complexType name="noColorPartOptionType">
    <xsd:restriction base="partOptionType">
        <xsd:element name="color"
        <xsd:element name="size"

An element type whose structure type is noColorPartOptionType might look like the following element:

<xsd:element name="noColorPartOption"

Given the preceding element type, the following element, which permits and requires only color, is valid in an XML instance:


Note the line containing 'maxOccurs = "0"'. This restriction enforces that despite the fact that the partOptionType specifies an optional size, the derived noColorPartOptionType specifies that size must not exist.

  • + Share This
  • 🔖 Save To Your Account