What is a DTD?
A DTD is a Document Type Definition. A DTD defines the structure and the legal elements and attributes of an XML document.
Why Use a DTD?
With a DTD, independent groups of people can agree on a standard DTD for interchanging data. An application can use a DTD to verify that XML data is valid.
An Internal DTD Declaration
If the DTD is declared inside the XML file, it must be wrapped inside the <!DOCTYPE> definition:
XML document with an internal DTD
<?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note>
In the XML file, select “view source” to view the DTD.
The DTD above is interpreted like this:
!DOCTYPEnote defines that the root element of this document is note
!ELEMENTnote defines that the note element must contain four elements:
!ELEMENTto defines the to element to be of type
!ELEMENTfrom defines the from element to be of type
!ELEMENTheading defines the heading element to be of type
!ELEMENTbody defines the body element to be of type
srcs docstore.mik.ua/orelly/xml/xmlnut, loc.gov