HomeXML Page 4 - Doing More With XML Schemas (part 2)
Big Brother Is Watching... - XML
In this second part, find out how to derive new element types by constraining existing ones, control access to your schema definitions, and redefine externally-provided schemas in place.
It's also possible to control whether or not schema designers can derive new datatypes from existing one, simply by specifying the level of extensibility allowed in the base definition. This is accomplished via the "final" attribute, which can accept any one of three values: "restriction", "extension" and "#all". Consider the following example, which illustrates:
In this case, I've specified that new types may *not* be derived from this type by extending or restricting it, via the "final" attribute. In order to verify that this works, try deriving a new type by extension and using that derived type in a document instance - your XML validator should display an error.
This ability to control the extent to which a base type can be used for further type derivations is very important when you're creating layered schema definitions; it can provide schema authors with an easy, efficient way to restrict misuse or erroneous use of a type definition, especially in the case of schemas which are widely used by many different applications.
You can specify a default "final" value for *all* the datatypes in a schema via the special "finalDefault" attribute, which must be included within the outermost <xsd:schema> element. In order to illustrate, consider the following code snippet, which allows derivation of new types from all existing definitions by restriction only.