Home > Articles > Web Services > XML

  • Print
  • + Share This
From the author of

Extending Complex Types

Much like other object-oriented languages, complex types often derive from other complex types. Derivations—similar to any other classification hierarchy—allow a programmer to specify additional element types and attribute types. The extension element type provides this derivation capability.

The next element describes an extension of the partOptionType complex type presented in the all element type section. Specifically, certain parts require a quantity:



<xsd:complexType name="multiplePartOptionType">
  <xsd:complexContent>
    <xsd:extension base="partOptionType">
      <xsd:all>
        <xsd:element name="color"
               type="xsd:token"/>
        <xsd:element name="size"
               type="xsd:token"
               minOccurs="0"/>
        <xsd:element name="quantity"
               type="xsd:positiveInteger"/>
      </xsd:all>
    </xsd:extension>
  </xsd:complexContent>
</xsd:complexType>

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

<xsd:element name="multiplePartOption"
       type="multiplePartOptionType"/>

Given the preceding element type, the following element is valid in an XML instance:

<multiplePartOption>
  <size>big</size>
  <quantity>3</quantity>
  <color>aquamarine</color>
<multiplePartOption>
  • + Share This
  • 🔖 Save To Your Account