Understanding
XML DTD with a sample code
An
XML DTD is the document that defines how an XML document should look
like. You can think of a DTD as an outline or a rule that should be
followed in creating an XML document. The number of nodes and child
nodes are defined for a particular tag in an XML document.
_______________________________________________
_______________________________________________
If
you know how to create or read a DTD document then you can create an
XML document based on that DTD. Knowledge on DTD would help you to find
out what went wrong in an XML document if that document fails the validation.
Consider the following DTD document:
<!ELEMENT
freeSoftware ( download+ ) >
<!ELEMENT download ( productName, link+ ) >
<!ELEMENT productName ( #PCDATA ) >
<!ELEMENT link ( #PCDATA ) >
In the
above code in the DTD, you can understand that the XML document created
based on that would have one or more <download> elements. Each
of these <download> element would have one <productName>
child node and one or more <link> child node. The '+' sign indicates
that the node can be present one or more times.