Home > Articles > Web Services > XML

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

This chapter is from the book

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. Example 17 shows some valid values for final.

Example 17 Valid Values for the Final Attribute in Simple Type Definitions

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

Example 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 4 because it attempts to restrict DressSize-Type.

Example 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