DTD and XSD Schema Tutorial Exercises
- XMLSpy is a comprehensive and capable XML IDE but unfortunately rather expensive.
XMLSpy is available in the CIS labs and will save you significant time and effort with your coursework so it is worth becoming familiar with this software.
Altova offer a 30 day free trial licence.
Several competing packages have emerged recently but nothing from the open source community offers the functionality of XMLSpy.
- Download the three goodBooks XML documents and their respective DTDs and XSDs from the course website.
- Experiment with making the documents invalid (but still well-formed) and revalidating them.
- It will take some time to explore XML Spy but it is worth the effort.
Try and explore...
- The different views; text, enhanced grid and schema (the browser view will not be useful until next week)
- The tests for well formed-ness and validity
- The tools for generating DTDs and XSDs from XML and converting between DTD and XSD
- Make the following changes to goodBooks2.dtd:
- Books can have more than one author, there should always be at least one.
- Add a new element to hold the price of a book.
- Add an attribute to the new price element to give the currency of the price.
The default currency should be "euros"
- Change goodBooks2.xml to test the changes and revalidate it.
- Make the same changes as specified above to goodBooks3.xsd.
Change goodBooks3.xml to match and revalidate it.
- Create a well formed XML document that contains some of the information in your coursework databases.
- How can you make sensible use of attributes in this example?
- Use XML Spy to create a DTD that describes your coursework XML and validate your document against it.
- Note how XMLSpy takes an informed guess as to your intended schema.
- Edit the DTD so that it is easier to read.
- Edit the DTD to match your intended schema.
- Use XML Spy to convert your DTD into an XSD and validate your document against it.
- There are some choices as to how you prefer the XSD structure.
- You could simply generate the XSD directly from your XML example but it would may be more difficult to correct XMLSpy's guesswork.