DTD Internal Declaration

Internal DTD Declaration :

<?xml version="1.0"?>
<!DOCTYPE bookDocument [
  <!ELEMENT Book    (name,author,type,pages)>
  <!ELEMENT name    (#PCDATA)>
  <!ELEMENT author  (#PCDATA)>
  <!ELEMENT type    (#PCDATA)>
  <!ELEMENT pages   (#PCDATA)>
   <name>Learn XML</name>

The above DTD definition can be interpreted as –

DTD ElementExplanation
!DOCTYPE bookDocumentdefines that the root element of this document is Book
!ELEMENT BookTells that the Book element contains four elements : "name,author,type,pages"
!ELEMENT nameTells that name element is of type "#PCDATA"
!ELEMENT authorTells that author element is of type "#PCDATA"
!ELEMENT typeTells that type element is of type "#PCDATA"
!ELEMENT pagesTells that pages element is of type "#PCDATA"

Explanation :

Consider the above xml document. We have created an document which is having all the information about the book.

Whenever we add any XML document then DTD document should be provided to ensure that all the elements in XML document are legal and predefined.

<!DOCTYPE bookDocument [

First line of the DTD document will provide us list of allowed nodes in a XML document.

<!ELEMENT Book  (name,author,type,pages)>

The above statement will allow only following elements inside the root element (i.e inside book element).

name,author,type,pages are only allowable elements inside the book.

So any element defined inside the book root element must be any of the 4 elements specified inside the above list otherwise that xml will not be treated as valid xml.