Learning About Document Type Definitions

Another piece of the puzzle that HTML 4 provided was a means by which web designers could move away from the haphazard practices of yesterday and embrace the longer-term ideals of standards. This came about with the creation of three distinct DTDs within HTML 4. Each of these definitions contains specific information about which elements and attributes are available in HTML and how they could be used, depending upon the goals of the designer.

A DTD is a plain-text document that contains rules about the way a given language works. In the case of HTML, the DTDs are publicly available at the W3C. Figure 1.9 shows a portion of a W3C DTD viewed within a web browser.

click to expand
Figure 1.9: A portion of the HTML 4.01 Transitional DTD as seen in the Opera browser

The Three Flavors of DTDs in HTML 4.0/4.01

Three types of DTDs, referred to as interpretations, were first defined in HTML 4 and later influenced HTML 4.01 and XHTML 1. These DTD interpretations are as follows:

Strict The Strict DTD is the most optimistic of the three, with almost all presentational elements and attributes completely unavailable to use if you want a valid document. (See the next section, “Compliance and Validation.”) The recommended means of addressing presentation at this level is, of course, CSS.

Transitional Also referred to as “loose,” this DTD was developed with the understanding that CSS was not then (and is still not now) completely available in all cases. The Transitional DTD allows for simple presentational elements and attributes, including even those that had been deprecated in favor of a better technology, such as the font element (note that this is even true in the XHTML 1 Transitional DTD). Ideally, document authors choosing a Transitional DTD understand that they are working toward the goals the Strict DTD embodies. To that end, while you can use deprecated elements in a Transitional DTD, you are not particularly encouraged to do so.

Frameset The Frameset DTD is specific to the creation of framesets, which as most readers are aware, is a different type of document from a conventional HTML page. Framesets can be considered the control documents that restructure a browser’s interface and give the designer control over how to do that. The Frameset DTD only includes information for frameset documents, so the only time you will use a Frameset DTD is when you are creating a frameset. Conventional pages within your frames can be marked up using any HTML language, version, and DTD.

No doubt you’re wondering how DTDs influence the way a document is read by browsers. The truth is that only recently did the inclusion of a DOCTYPE citing a specific DTD influence the way a given browser interpreted a document. (See the "DOCTYPE Switching" sidebar later in this chapter.) For the most part, if you include something nonstandard in a document, the browser’s going to display it if it knows the markup you’re using. Following a DTD means following the language’s rules, and this relates mostly to the creation of compliant and valid documents.

Compliance and Validation

Two key concepts when working with web standards include compliance and validation:

  • A compliant document is one that conforms to the DTD that is referenced by its DOCTYPE.

  • A valid document is one that is tested for compliance using a validator such as that provided by the W3C, http://validator.w3.org/.

Note 

With any application, bugs exist. So it is with validators, too. For a helpful guide on commonly encountered validation problems, see “Liberty! Equality! Validity!” at http://devedge.netscape.com/viewsource/2001/validate/.

There have been some arguments about the usefulness of validation. I consider validation to be an important process when working seriously with HTML, XHTML, and CSS. Validation aids in education by providing warnings and errors regarding document compliance.

The only consideration is that validation errors can be as confusing as grammar rules in a Microsoft Word document! You have to learn a bit of process when it comes to troubleshooting.

Note 

You’ll step through the validation process with HTML and XHTML in this chapter, and you will learn to validate CSS later in the book. Interestingly, the W3C validator is the most used service of the W3C.

Comparing DTDs in HTML 4

A good way to learn a bit about the way DTDs work is to compare portions of them with each other. In this case, first examine the DTD portion in Listing 1.2.

Listing 1.2: Excerpt from HTML 4.01 Strict DTD—Paragraphs

start example
<!-—========= Paragraphs =========—-> <!ELEMENT P - O (%inline;)* -— paragraph —-> <!ATTLIST P %attrs;          —- %coreattrs, %i18n, %events -— >
end example

Notice how this DTD portion shows how paragraphs are handled in HTML 4.01 Strict. The only attributes allowed are core attributes (%coreattrs) needed for style, scripting, and accessibility (id, class, style, title); internationalization attributes (%il8n) required for internationalization (lang, dir); and event attributes (%events), used for scripting as well (onclick, onmouseup, etc.).

Now examine Listing 1.3, which describes how paragraphs are handled in HTML 4.01 Transitional.

Listing 1.3: Excerpt from HTML 4.01 Transitional DTD—Paragraphs

start example
<!-—========= Paragraphs =========—-> <!ELEMENT P - O (%inline;)* -— paragraph —-> <!ATTLIST P %attrs;           -— %coreattrs, %i18n, events —- %align;           -— align, text alignment —- >
end example

The attributes in this DTD are a bit different. You’ll notice that the align category of attributes is included as well (align=x where x is left, right, center or justify). Alignment isn’t allowed in the Strict DTD because of the idea that presentation should be separated from the document structure and its content.

 Note  The HTML 4.01 Strict DTD can be found at www.w3.org/TR/html401/sgml/dtd.html . The HTML 4.01 Transitional DTD is available at www.w3.org/TR/html401/sgml/loosedtd.html . All of the DTDs in this chapter are public and online at the W3C website, www.w3.org/.



Cascading Style Sheets(c) The Designer's Edge
ASP.NET 2.0 Illustrated
ISBN: 0321418344
EAN: 2147483647
Year: 2005
Pages: 86

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net