HTML and CSS Reference
In-Depth Information
After understanding the difference between block-level and inline elements, nesting elements is rather
straightforward. Empty elements, such as img or hr , cannot contain other elements. Some elements have restrictions
for not only the elements but also the data types they can contain (for example, the contents of script elements should
be CDATA). Violating the nesting order of element might destroy the DOM structure of the document, which makes
rendering unreliable, risking the usability of the web page.
XHTML Document Structure
The XHTML document structure is similar to that of HTML in the sense that there is a head and a body section;
however, additional restrictions apply. Since XHTML documents are XML documents too, they begin with an XML
declaration not used in HTML. Moreover, there are several document types and profiles to choose from, depending
on the main purpose of the web document being developed.
XML Declaration
The very first line in XHTML documents is usually the optional XML prolog (its application is recommended by W3C).
The most commonly used XML declaration looks like Listing 3-35.
Listing 3-35. The Most Commonly Used XML Declaration
<?xml version="1.0" encoding="utf-8"?>
No content is allowed to precede the declaration (except an optional byte-order mark).
Although the character encoding is optional only, it is highly recommended.
Some older browsers cannot handle the XML declaration. The web page might become invisible, or the content
is rendered incorrectly (for example, in IE6). IE7 ignores the XML prolog and correctly renders the content in Strict
Mode (discussed in Chapter1).
Document Type Declaration
Similar to HTML, XHTML documents use a specific Document Type Declaration 16 to identify the document type
being used.
Generally, transforming an XHTML document into another XHTML document type is straightforward, especially
if XHTML 1.0 Strict elements are applied exclusively. However, care must be taken when performing such an action
because of the differences between the specifications. XHTML 1.0 Transitional is much more permissive, and
changing the Document Type Declaration of these documents will probably result in numerous errors that should be
justified in order to obtain a valid XHTML 1.0 Strict, XHTML 1.1, or XHTML5 document.
Until recently, the former Quality Assurance Interest Group at W3C maintained a “Recommended list of Doctype
declarations” [50]. Although it could be considered a “list of valid DTDs,” it is not complete; thus, some of the newer
as well as the most up-to-date document types are not listed (e.g., Mobile Profile, XHTML 2.0, or XHTML+RDFa),
partly because the group closed in 2007. This does not affect the application or validation of such documents. Some
non-W3C validators use the previous list and give warnings if a document type missing from that list is used. Such
warnings are often false positives, because some of the less used, earlier DTDs as well as the latest document types are
not on the list.
16 Prior to XHTML5
 
Search WWH ::




Custom Search