Apr 3, 2008

XML Document Type Definition ( DTD )

XML DTD

Document Type Definition (DTD)

In order to use DTDs with XML, the reader is encouraged to learn about the structure of DTDs. The document called "Document Type Definition (DTD)" on this website gives a more thorough explanation about how to read and construct a DTD than this document. The DTDs in this document are very basic and should, however, be easy to understand even for those who don't have familiarity with DTD's.

The DTD, whether included as part of the XML file or external to the XML file is used to define content. The DTD is used to determine the elements allowed in the file and which elements can be contained in other elements. It also describes the number of times specific elements may be contained in other elements.

The DTD document on this website was written for SGML DTDs and the main difference lies in the fact that XML requires a beginning and ending tag for all elements. SGML does not have this requirement.

Element Declaration

Therefore in an SGML DTD an element tag for the <HR> element is:

<!ELEMENT HR - O EMPTY -- horizontal rule -->

If written for XML, the DTD would be:

<!ELEMENT HR EMPTY -- horizontal rule -->

The difference between the two examples is that the XML <HR> declaration does not define whether the element requires a closing tag as done with the "- O" text. This is because all elements in XML are required to have closing tags and therefore defining whether a closing tag is required is pointless.

No comments:

Post a Comment

Popular Posts