- Simple type varieties
- Simple type definitions
- Simple type restrictions
- Facets
- Preventing simple type derivation
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 917 shows some valid values for final.
Example 917. Valid values for the final attribute in simple type definitions
final="#all" final="restriction list union" final="list restriction extension" final="union" final=""
Example 918 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 94 because it attempts to restrict DressSizeType.
Example 918. Preventing type derivation
<xsd:simpleType name="DressSizeType" final="restriction list"> <xsd:restriction base="xsd:integer"> <xsd:minInclusive value="2"/> <xsd:maxInclusive value="18"/> </xsd:restriction> </xsd: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 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.