If you
know the different components and the syntax of a DTD statement you
can easily write it. before writing a DTD you should also know how your
XML file elements should be present. To start with let us consider an
example XML file where you need the root node to be <books>. This
node can have one or more <book> node. For this you will be writing
the DTD statement as,
_______________________________________________
<!ELEMENT
books (book+) >
The plus
sign indicates that the book node can be one or more. If the book node
is to have two other child nodes named title and author. The author
for a title can be more than one and at least one. So the DTD statement
for that would be,
<!ELEMENT
book (title, author+) >
<!ELEMENT title (#PCDATA) >
<!ELEMENT author (#PCDATA) >
The data
that is present within the title tags and the author tags are text that
is parsed by the parser. Hence they are written as #PCDATA.
If you
have tools like XMLSpy you can generate a DTD from the XML document
easily with the inbuilt tool for that purpose.