Page 618 - Beginning PHP 5.3
P. 618
Part III: Using PHP in Practice
These three DTDs complement their HTML counterparts, and are, in fact, quite similar. If you enter these
URLs in your browser, you ’ ll actually see the DTD in plain text. (You might need to download the DTD
file and open it in your text editor.)
Here is a portion of the XHTML Strict DTD showing how the img (image) element is declared:
< !--
To avoid accessibility problems for people who aren’t
able to see the image, you should provide a text
description using the alt and longdesc attributes.
In addition, avoid the use of server-side image maps.
Note that in this DTD there is no name attribute. That
is only available in the transitional and frameset DTD.
-- >
< !ELEMENT img EMPTY >
< !ATTLIST img
%attrs;
src %URI; #REQUIRED
alt %Text; #REQUIRED
longdesc %URI; #IMPLIED
height %Length; #IMPLIED
width %Length; #IMPLIED
usemap %URI; #IMPLIED
ismap (ismap) #IMPLIED
>
< !-- usemap points to a map element which may be in this document
or an external document, although the latter is not widely supported -- >
On the first line following the comment, the img element is declared as EMPTY (that is, it contains no
content, only attributes). Following the ELEMENT line is a list of attributes that may be included inside the
img tag in an XHTML document. Those of you familiar with HTML and XHTML no doubt recognize
the src attribute as the URI that specifies the location of the image file; this attribute is REQUIRED .
So this portion of the DTD for XHTML documents specifies that it is permissible to include img elements
in such documents. If the DTD is referenced in an XHTML document, and the document includes an img
element with an appropriate src attribute, the document could be said to be valid (at least as far as the
img element is concerned). However, if you tried to include an element name imge or image or images ,
a validating XML parser would produce an error, because according to the DTD such elements are not
declared, and therefore the document is not valid.
Referencing DTDs
To reference an external DTD, you use a DOCTYPE declaration. This declaration indicates the name and
the location of the DTD. For example, this line shows how to reference the XHTML Strict DTD:
< !DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd” >
580
9/21/09 9:17:45 AM
c19.indd 580 9/21/09 9:17:45 AM
c19.indd 580