Databases - XML and DTD

XML and DTD

In this lab exercise you will get some hands on experience with the creation of a DTD and an XML schema.

  1. Create a DTD-file named contacts.dtd for an address book which should be structured so that valid XML files contain the priceless information about contacts. It should be structured as follows:
    • Multiple (ranging from 0 to infinity) contacts should be stored
    • Each contact has:
      • a first name
      • a last name,
      • at least one (but maybe more) addresses,
      • at least one (but maybe more) e-mail address,
      • at least one (but maybe more) phone number,
      • an attribute stating whether this contact is a "business" contact or a "personal" contact (required)
    • An address should contain:
    • a street name,
    • a house number,
    • a zip code,
    • a city name

  2. Construct a valid XML file contacts.xml implementing this DTD with the following two contacts:
    • Gerrit de Vries (business contact):
      • Dorpsstraat 3 - 0101UK - BuitenDorp
      • Pleinstraat 35 - 9101BK - BinnenDorp
      • E-mail: gerritdevries@binnendorp.nl
      • Tel: 232-111-223-22
      • Tel: 211-278-990-11
    • Jan de Boer (personal contact):
      • Rijksstraatweg 9 - 9919KK - Klinkerstad
      • E-mail: jandeboer@mooiklinkerstad.nl
      • Tel: 221-185-492-91

  3. With the command:
    xml val filename

    you can check the well-formedness and validate your XML file, and with the command:

    xml val -d dtd_file xml_file

    you can only validate (no conformance).

    Execute these commands on the XML file that you just generated. If no error message is shown, then your XML is correct.

  4. Now we want to see what happens if we do something wrong. Modify your XML file such that it is well-formed, but not validated.