Why use a DTD?
XML provides an application independent way of sharing data. With a DTD, independent groups of people can agree to use a common DTD for interchanging data. Your application can use a standard DTD to verify that data that you receive from the outside world is valid. You can also use a DTD to verify your own data.
Internal DTD
This is an XML document with a Document Type Definition: (Open it in IE5, and select view source)
<!DOCTYPE note [
]>
Tove
Jani
Reminder
Don’t forget me this weekend!
The DTD is interpreted like this:
!ELEMENT note (in line 2) defines the element “note” as having four elements: “to,from,heading,body”.
!ELEMENT to (in line 3) defines the “to” element to be of the type “CDATA”.
!ELEMENT from (in line 4) defines the “from” element to be of the type “CDATA”
and so on…..
External DTD
This is the same XML document with an external DTD: (Open it in IE5, and select view source)
Tove
Jani
Reminder
Don’t forget me this weekend!
This is a copy of the file “note.dtd” containing the Document Type Definition