XML Schema – simple types, keys and references

References for subject 3


Tutorials and hints:

Simple types

Current examples are in XML03.zip.

Look at the examples in types.xsd. Try to validate the example document. Check if the constraints are really verified.

The directory types/jaxb_generated contains Java classes which were generated by JAXB basing on the schema. Look (in particular at Test.java) what are the corresponding Java types used for subsequent XML Schema types (don't overlook bad-price and bad-phone). Is it important to use the most appropriate data type in XML Schema?

Task 1.

Start with students12.xsd.

  1. Define a simple type for PESEL.
  2. Add an optional address information to the Person type (students and teachers). Define appropriate simple types for address fields (postal code, list of known countries...)
  3. Restrict the maximum length of some text fields.

Keys and references

Example definitions can be found in students12.xsd.

Task 2.

Continue working with your version of students12.xsd.

Elements /school/teachers/teacher and /school/students/student contain data of all teachers and students in the school. In a lecture, elements teacher and registered-students/student should refer to those records. You have to modify the definition appropriately:

  1. Add attributes teacher-id and student-id to the records. (Find TODOs in the schema source.)
  2. Add the same attributes to the referring elements (which are now empty). (Find TODOs in the schema source.)
  3. Define appropriate keys and references to make a document consistent.

Target namespace

Look at the examples ns/ns2.xsdns/ns4.xsd to see different ways of handling namespaces and prefixes in schemas which provide a target namespace.

Task 3.

  1. Add a target namespace to your schema (you may work on a separate copy of it).
  2. Make the schema consistent (fix broken references to global elements or types).
  3. Change the information about schema location in the example document. (Generate a sample document to get a hint from Eclipse).
  4. Change the document and validate it.
  5. Fix keys and references, unless you've already done it.

Task 4.

Currently all lectures take place in one building, so it is enough to identify rooms by their numbers.

We want to extend our model to allow more than one building.

  1. Add a building name to the room information.
  2. Change key and keyref definitions, so that rooms are identified by pairs: (building, number). Adjust the meeting definition accordingly.

Valid XHTML 1.1Valid CSS