DTD Internal DeclarationPritesh
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)> ]> <Book> <name>Learn XML</name> <author>Pritesh</author> <type>Scripting</type> <pages>100</pages> </Book>
The above DTD definition can be interpreted as –
|!DOCTYPE bookDocument||defines that the root element of this document is Book|
|!ELEMENT Book||Tells that the Book element contains four elements : "name,author,type,pages"|
|!ELEMENT name||Tells that name element is of type "#PCDATA"|
|!ELEMENT author||Tells that author element is of type "#PCDATA"|
|!ELEMENT type||Tells that type element is of type "#PCDATA"|
|!ELEMENT pages||Tells that pages element is of type "#PCDATA"|
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.