XML/DTD Laboratory Session
The purpose of this laboratory session is to help you learn about
XML and DTDs. To do so, you will be asked to use a text editor to
create XML files representing information about two different
applications, along with an appropriate DTD in each case.
You will also be asked to check whether or not your XML representation
is valid with respect to the DTD using an online validator.
The information to be represented in each case is as follows.
Consider an application in which the stock of new and used
cars held by a car dealer is to be represented in XML.
stock of the dealer comprises zero or more
cars, each of which is either a
new-car or a
used-car. For a
new-car, information on
price are recorded. For a
price are recorded, along with optional information
condition of the car.
condition contain text.
Consider an application in which the results of football games
are to be represented in XML. (The description below is deliberately
more open-ended than the one above.) For each game, we want to be
able to represent the two teams involved, which one was playing at home,
which players scored goals (some of which may have been
penalties) and the time when each was scored, and which players were shown
yellow or red cards. You might use some attributes this time, for practice.
See the English
Premiership results for some sample data (click on the > icon to the left
of a result to see the details about goals and cards).
In each case above, you should follow the following steps.
- Create the XML file:
Choose a directory in which you will create the XML file, which should
have an extension of
Use a text editor, such as Textpad, to enter information in XML
which conforms to the specification of the application
(do not worry about the DTD yet). You should
represent all the information using elements rather than
attributes. You should include enough information to
demonstrate each of different structures which are allowed.
Remember to include the XML declaration
at the beginning of the file.
- Check that the XML file is well-formed:
Open the file you created in (1) using a browser to check that
it is well-formed (the browser will give an error if it is not).
Modify the file until it is well-formed.
- Create the DTD:
- Now modify the XML file created in (1) to include an
for documents of the type you have designed,
trying to ensure that the XML representation
you created is valid with respect to this DTD.
Validate the XML file:
Go to the page for the W3C Markup
validation Service. You can upload your file to the service for
validation. The results of the validation will be presented on a separate page.
(Don't worry if you receive a warning about a missing
Modify your XML file until it is valid.
Invalidate the XML file:
If you produced a valid XML document straight away or only had to correct
a couple of mistakes, now modify your file in ways that you believe make
it invalid and check that you understand the error messages returned by
the validation service.