Building XHTML DTD Structure Element and Attribute Declarations

an article added by: Albert Lichtblau at 06022007


In: Categories » » HTML XHTML and CSS » Building XHTML DTD Structure Element and Attribute Declarations

Building Structure: Element and Attribute Declarations After all of these preliminaries, it's finally time to make some real declarations, creating the elements and attributes partly described by the entities established so far. This portion of the DTD is broken down into segments that reflect groupings of element types, foreshadowing to some extent the modularization process that XHTML 1.1 will perform. If you have trouble getting your XHTML documents to validate, you need to explore this portion of the DTD to track down the content models you need to support. The three DTDs have slightly different sets of declarations, as noted next.

Document structure The top-level declaration needed to create an XHTML document is the html element. The html element's role as a container gives it a very simple structure in the strict and transitional DTDs – it can contain a single head element and a single body element with only the internationalization and namespace declaration for attributes. In the frameset DTD, however, the content model changes dramatically to a head element and a frameset element, which limits the use of the frameset DTD to documents that use frames or the noframes element. Effectively, frames are segregated from the rest of XHTML. Strict and transitional documents may appear within those frames, although the strict DTD is missing some key tools for working with frames (such as the target attribute).

Document head The head element primarily is a container for metadata – information describing the document that follows. Some of this metadata (such as style sheets) may be applied to the document as part of the presentation; other parts help systems outside the document to categorize the document and reference it appropriately. While the contents of the head element are similar in all three DTDs, some subtle differences are important to note. The strict DTD omits the long-deprecated isindex element, as well as the target attribute that allows the base and link elements to specify a target frame in addition to a URI. This section also defines a script element that may appear in either the head or the body element and a noscript element that may appear only in the body. The declaration for noscript in the strict DTD only permits the use of block elements, while the version in the other DTDs allows anything defined in the Flow entity, including both block and in-line elements.

Tip The declaration for the head element in all three DTDs demonstrates how XML sometimes requires complex notation to state something as simple as "one title

Frames (frameset and transitional only) This section follows the document head section in both the transitional and frameset DTDs, and is omitted entirely in the strict DTD. The transitional DTD only declares two elements – the iframe and noframes elements. Meanwhile, the frameset DTD declares those and the frameset and frame elements – the two core elements for creating frame-based Web sites. The noframes element, used in a transitional document, may contain any elements appearing in the Flow entity, while the frameset DTD restricts its content to body.

Document body This next section creates the body and div elements in all three DTDs. The body element receives two event attributes – onload and onunload. This is in addition to the event attributes used for other HTML elements, which provide support for scripts that run when the document is opened and closed. In the strict DTD, only block elements may appear directly inside the body element, while the transitional and framset DTDs permit anything listed in the Flow parameter entity. The most significant general difference among the DTDs is the strict DTD's omission of the formatting properties (notably bgcolor) supported by the other DTDs. Similarly, the strict DTD's version of the div element omits the TextAlign entity that provides the align attribute (another formatting feature).

Note In HTML 4.0, onunload and onload were commonly written onUnload and onLoad. In XHTML, they must be entirely lower-case.

Paragraphs and headings The next two sections describe some of the core components of XHTML: the p element and the h1-h6 heading elements that together formed the backbone of HTML documents since the very beginning of the Web. All of these elements are defined so that they may contain only in-line elements (as defined in the Inline entity, described in the preceding Text Elements section.). The transitional and frameset DTDs also provide use of the align attribute through the TextAlign entity.

Lists The list section defines XHTML's ordered, unordered, and definition lists. In the strict DTD, the declarations are very simple; they apply only the core attributes (defined in the attrs entity) using the Inline and Flow entities to identify content models for list items. In the transitional and frameset DTDs, the type, compact, and start attributes give document authors a lot more control over how they can present the lists.

Other elements The next few sections of the DTDs define elements that don't fit easily into categories. The horizontal rule (hr), preformatted text (pre), block quotation (blockquote), centering (center, which only appears in the transitional and framework DTDs), and insert and delete editing elements (ins and del) are defined here.

Anchor element The anchor element (a), another difficult element to categorize, comes next. The a element defines its content model using the a.content entity (defined in the section for exclusions). Its hyperlinking features are defined using its attributes, which are the same in all the DTDs except that the strict DTD doesn't allow the target attribute to identify the frame in which content should appear.

Note Strange though it may seem, the a element is one of the most likely elements to face significant change in the immediate future as the XLink standard is integrated with XHTML.

In-line elements The in-line elements section defines an enormous number of XHTML element types, all of them intended for use within text. Almost all of them are defined using the attrs entity for their attributes and the Inline entity for their content. The transitional and frameset DTDs include the u, s, strike, basefont, and font elements, which were deprecated in HTML 4.0 and aren't present in the strict DTD. Similarly, the br element loses the clear attribute, commonly used in complex layouts.

Objects and applets The next two sections define the somewhat similar object and applet elements for including software objects and Java applets within XHTML documents. The strict DTD omits a few formatting descriptions from the object element and completely omits the applet element – considering it to be a duplication of the object element's functionality. At the same time, the object element loses the formatting-oriented hspace, vspace, and border attributes. Also worth noting, although without significant impact in XHTML 1.0, is a suggestion to drop the param element. The W3C's Resource Description Framework (RDF) allows more flexibility in representing information and could eventually permit attributes to replace param elements in the object element. This isn't, however, implemented in any of the DTDs.

Images and image maps The next two sections define elements for images (img) and client-side image maps (map and area). The img element receives a few extra formatting attributes in the transitional and frameset DTDs, while the area element loses the target attribute in the strict DTD.

Forms XHTML 1.0 provides the same form support as HTML 4.0. Apart from a slight change to prevent form elements from containing other form elements (which is prohibited), most of these declarations are fairly simple. As usual, the transitional and frameset DTDs provide additional formatting options.

Tables XHTML 1.0 provides the same table support as HTML 4.0. Most of these declarations are fairly simple, although the table element is notable for prohibiting direct textual content. (If you have any text floating in your table elements that isn't contained by another element, be sure to remove it!) As usual, the transitional and frameset DTDs provide additional formatting attributes, such as bgcolor, height, width, and some alignments.

Beyond the XHTML DTDs While the XHTML DTDs describe an enormous amount of document structure, there remain a few key parts of XHTML that can't be contained neatly within the DTD. XML DTDs only permit elements to describe their own content – they aren't, for instance, allowed to prohibit content within the elements they contain. To enforce such requirements, the W3C includes a normative (required) appendix to the XHTML 1.0 specification, "Element Prohibitions" (http://www.w3.org/TR/xhtml1/#prohibitions). While validating XML parsers won't catch these problems, XHTML applications should check for these situations. In a significant sense, the XHTML 1.0 DTDs represent only one piece of a complex specification. While learning to read the DTDs can give you lots of insight into how the W3C is implementing XHTML, there's a reason that these formal declarations are relegated to an appendix. They are an important part of the specification – the appendix is, in fact, normative – but they provide only part of the XHTML picture.

legal notice

Our website is not responsible for the information contained by this article. Web-articles is a free articles resource.
Suggestion: If you need fresh, daily updated content for your website, feel free to use our service. Click here for more information.

Useful tools and features

Link to this article from your page    Send this article to you or to a friend
If you like this article (tutorial), please link to it from your web page using the information above.

related articles

1. XML and XHTMLs Maximum Structure
Coding Styles— XML and XHTML's Maximum Structure Overview XML parsers are far more brutal about rejecting documents they don't like than are HTML browsers. XML's clear focus on structure demands that the practices described in the previous chapter must change. However, most of those changes shouldn't cause more than minor inconveniences – at least for newly created documents. Note If reading this chapt...

2. XML and CDATA
Processing instructions XML also enables developers to pass information to the application through processing instructions (often called PIs). Processing instructions use a similar syntax to the XML declaration, although the rules for them are much less strict. Processing instructions begin with <? and end with ?>, but the developer generally dictates their contents. The first bit of text before a space appears in a PI is called the target. The target must start with a letter, unde...

3. lang Internationalization
Internationalization: xml:lang and lang Internationalization (often abbreviated i18n because 18 characters appear between the i and the n) gets a significant boost with the shift to XML primarily because of XML's use of Unicode as the underlying character model. While not every document needs to encode Chinese, Cyrillic, Arabic, and Indian characters, Unicode makes it possible for all of these forms to exist within a single document. In addition, XML and XHTML allow for the possibility of other e...

4. Anatomy of an XHTML Document
The transition from HTML to XHTML will come with a fair number of bumps. While later chapters introduce tools to help you get past those bumps – and figure out where they come from – this chapter examines what's going to change and demonstrates a few strategies for handling those changes. Along the way, we visit the ghosts of browsers past and explore problems that exist in current browsers. In turn, you discover how prepared and unprepared various tools are for XHTML. Note Som...

5. Converting to strict HTML and XHTML
Converting to strict HTML You start out by declaring your intentions to use the strict HTML 4.01 DTD by putting the appropriate DOCTYPE declaration at the head of the document: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> Now the first section of the document, including the HTML opening tag and the HEAD element and its contents, is fine except for one line. The SCRIPT element no longer supports a LANGUAGE at...

6. Reading the XHTML DTDs A Guide to XML Declarations
Reading the XHTML DTDs: A Guide to XML Declarations Although the W3C has long had document type definitions (DTDs) for HTML, few developers actually use those DTDs as a foundation for learning HTML. XHTML 1.0 simplifies those DTDs with the slightly friendlier XML syntax – they previously used SGML's more complex syntax – and the increased emphasis on validation may lead developers to explore them more closely. Making good use of XHTML 1.1 requires some level of ...

7. Defaulting attribute values XHTML DTDs
XML 1.0 also provides a set of tools for specifying what happens if an attribute isn't declared within an element. Four different possibilities exist, including "the attribute just isn't there"; "the attribute must be there, period"; and "the attribute has this value, period." You already have seen a few uses of these choices in the preceding declarations. In the img element, for instance, the src and alt attributes are required (#REQUIRED); meanwhile, most of the rest of its attribute content is optio...