Knowing
the different components of a DTD file would help you in understanding
how the XML file is formed based on a DTD.
_______________________________________________
_______________________________________________
The
DTD file defines the rules on how the elements of the XML file should
be organized. The number of child nodes for a particular node and the
type of value of the particular node are all defined in a DTD.
Look at
the following DTD file,
<!ELEMENT
books ( book+ ) >
<!ELEMENT book ( title, author ) >
<!ELEMENT title ( #PCDATA ) >
<!ELEMENT author ( #PCDATA ) >
The 'ELEMENT'
defines that the name that follows that word is an element of the XML
file. Take the first statement. In that there is an element 'books'
defined and that 'books' element can have any number of 'book' element
as its child. That is why it is given as 'book+'. Now come to the second
statement. It states that the 'book' element can have child elements
as 'title' and 'author' and there can be only one 'title' and one 'author'
element within the 'book' element. That is why the '+' is missing in
it. The 'title' and the 'author' are text nodes that have some value
in it. That is denoted by #PCDATA. Based on the above definition a typical
XML document might look like,
<books>
<book>
<title >Book Title 1</title>
<author>Author 1</author>
</book>
<book>
<title>Book Title 2</title>
<author>Author 2</author>
</book>
<book>
<title>Book Title 3</title>
<author>Author 3</author>
</book>
</books>
There could
be any number of 'book' elements in this XML file according to the DTD
document.