Validation with Document Type Definitions (DTDs) - Creating an XML Prolog
(Page 3 of 4 )
A Prolog is the first thing in your XML document, and it is the first thing that will get processed. It contains five parts, some of which are optional. These parts are the declaration, the DOCTYPE declaration, instructions for the processor, white space, and comments.
XML Declaration
We have gone over this portion many times, so I will not bother to cover it again here. All you need to know now is that it is a part of the XML Prolog.
DOCTYPE
The DOCTYPE declaration tells the processor where to find your DTD. It is not truly XML, and is therefore written using SGML syntax. Here is an example of how you write the DOCTYPE: <!DOCTYPE albums SYSTEM “albums.dtd”>
This is a breakdown of how the above example works. !DOCTYPE signifies the beginning of a DOCTYPE declaration. Albums is the name of the DTD that we are using. SYSTEM “albums.dtd” is a way of telling the processor to look for a file called “albums.dtd.”
There are more ways to call a DTD file. In our above example, we are using a URI or a Uniform Resource Identifier. These are similar to URLs and truthfully, a URL is a form of a URI. The way we set up our reference to the DTD file via a URI above, means that the file “albums.dtd” is located in the same folder as our XML file. If your DTD file were located outside of the folders of your XML file, you would simply point to the URL where the DTD is located, such as http://www.mywebsite.com/file/albums.dtd.
Commenting
You should be familiar with the concept of commenting. It is the process of leaving notes/comments in your programs for other programmers or yourself. The computers and processors cannot see these comments and ignore them. Here is how you would write a comment in your file:
<! – I am leaving a comment -- >
You must never leave a comment inside of an element and always make certain that you do not write a hyphen or double hyphen inside of the comment text, as it will confuse the processor. Here is what I mean:
<! – Hi – How are you? -->
When the processor sees the double hyphen after the word “Hi,” it will think that that is the end of the comment and treat the rest as normal syntax, causing errors.