XML Schema – simple types, keys and references

References for subject 4

Recommendations and specifications:

Examples -- the same package with some new additions: XML03.zip

Keys and references together with target namespace

Finish the last week exercises: add the following identity constraints and make them working together with the target namespace declaration.

Task 1.

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.

Task 2.

  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 3.

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.

Alternatives

Look at the examples in the Relax NG Tutorial to get an overview of its capabilities.

You may try to validate some examples using xmllint --relaxng command.

Here you can find instructions how to run XML Schema 1.1 validation in Java (using beta the version of Apache Xerces parser).

I hope we will spend some time on discussion regarding your assessment projects and the schemas you are preparing...

We're going to start some programming next week.


Valid XHTML 1.1Valid CSS