Home > Articles

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

This chapter is from the book

9.5 Preventing simple type derivation

XML Schema allows you to prevent derivation of other types from your type. By specifying the final attribute in your simple type definition, you may prevent derivation of any kind (restriction, extension, list, or union) by specifying a value of #all. If you want more specific control, the value of final can be a whitespace-separated list of any of the keywords restriction, extension, list, or union. Extension refers to the extension of simple types to derive complex types, described in Chapter 14, "Deriving complex types." Example 9–17 shows some valid values for final.

Example 9–17. Valid values for the final attribute in simple type definitions

final="restriction list union"
final="list restriction extension"

Example 9–18 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 MediumDress-SizeType in Example 9–4 because it attempts to restrict DressSizeType.

Example 9–18. Preventing type derivation

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

If no final attribute is specified, it defaults to the value of the finalDefault attribute of the schema element. If neither final nor finalDefault are 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