Introduction to DTDs
DTD Exercise I
In the first part of this exercise, we will create a simple DTD for poetry. In the first part of the exercise, only use the elements below:
- poem (which will be the root element)
- verse
- line
- title
- note
- author
To help you with the DTD syntax, we’ve created a DTD Cheat Sheet. Open up the PDF and keep it handy when you are creating the DTD. Create the DTD in a parsing editor such as oXygen. oXygen understands DTD syntax, and once you begin creating the document instance, it will give error messages if you do something wrong. However, until the XML code is in place, you will get parsing errors.
Start by opening oXygen, and then choose the top left icon, the new document icon, and then choose 'XML Document'. Begin by creating the root element right below the XML declaration.
1 2 3 |
<?xml version="1.0"?> <!DOCTYPE poem [ ]> |
After you create your DTD, see if the DTD will model your poem the way you expect. To do this, create a document instance right below the DTD. Once everything works correctly, go back and add occurrence indicators to further define the behavior of the elements.
You can try to create the DTD on your own, or follow along with this video