Home > Articles > Web Services > XML

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

8.5. Preventing simple type derivation

XML Schema allows you to prevent derivation of other types from your type. By specifying the final attribute with a value of #all in your simple type definition, you prevent derivation of any kind (restriction, extension, list, or union). If you want more granular control, the value of final can be a whitespace-separated list of any of the keywords restriction, extension, list, or union. The extension value refers to the extension of simple types to derive complex types, described in Section 13.4.1 on p. 306. Example 8–20 shows some valid values for final.

Example 8–20. Valid values for the final attribute in simple type definitions

final="#all"
final="restriction list union"
final="list restriction extension"
final="union"
final=""

Example 8–21 shows a simple type that cannot be restricted by any other type or used as the item type of a list. With this definition of DressSizeType, it would have been illegal to define MediumDressSizeType in Example 8–4 because it attempts to restrict DressSizeType.

Example 8–21. Preventing type derivation

<xs:simpleType name="DressSizeType" final="restriction list">
  <xs:restriction base="xs:integer">
    <xs:minInclusive value="2"/>
    <xs:maxInclusive value="18"/>
  </xs:restriction>
</xs:simpleType>

If no final attribute is specified, it defaults to the value of the finalDefault attribute of the schema element. If neither final nor finalDefault is specified, there are no restrictions on derivation from that type. You can specify the empty string ("") for the final value if you want to override the finalDefault value.

  • + Share This
  • 🔖 Save To Your Account