HomeXML Page 3 - Doing More With XML Schemas (part 2)
The Next Level - 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.
Now, deriving a new datatype by extending the characteristics of an existing one is just one way of getting the job done. The XML Schema specification also supports one other way of deriving new datatypes: by restricting, or constraining, the characteristics of existing types.
In order to understand this, let's go back to the analogy on the previous page, and consider using the "Jedi" datatype as the base for another datatype: "JediMaster" (according to http://www.starwars.com/databank/organization/thejediorder/index.html, Jedi Masters are "those who have shown exceptional devotion and skill in the Force.")
In other words, a "JediMaster" possesses all the characteristics of a "Jedi"...with one additional constraint: a very high midi-chlorian count. Therefore, it is possible to define a "JediMaster" datatype simply by adding a restriction to the definition of the "Jedi" datatype - as demonstrated below:
Want to verify that I'm speaking the truth? Take the XML sample on the previous
page, alter it to use the new "JediMaster" datatype, and pass it through an XML validator.
This time, you should see no errors - indicating that the restriction you've
imposed while deriving the new datatype is in effect.
Note also that when deriving by restriction, it is necessary to repeat the definition of all elements in the derived complex type from my original type. As a result, all elements of type "JediMaster" will also be acceptable as elements of type "Jedi".