The XHTML Standard and Internal Parameter Entities

Now would be a good time to introduce a new standard that is being created for HTML. This new standard is called XHTML; it is also represented in a new version of HTML (version 4.01). The World Wide Web Consortium (W3C) standards committee is currently working out the last details of the standard, which is all about doing what we've done in the last few chapters, XMLizing HTML. You can find information about this standard by visiting http://www.w3.org.

Basically, the XHTML standard introduces two content models: inline and block. The inline elements affect individual text elements, whereas the block elements affect entire blocks of text. These two elements are then used as child elements for other elements.

Inline entities and elements

The XHTML standard provides the following declarations for defining a series of internal parameter entities to be used to define the inline elements:

  <!ENTITY % special "br
                      | span
                      | img">
  <!ENTITY % fontstyle "tt
                        | i
                        | b
                        | big
                        | small">
  <!ENTITY % phrase "em
                     | strong
                     | q
                     | sub
                     | sup">
  <!ENTITY % inline.forms "input
                           | select
                           | textarea
                           | label
                           | button">
  <!ENTITY % inline "a
                     | %special;
                     | %fontstyle;
                     | %phrase;
                     | %inline.forms;">
  <!-- Entities that can occur at block or inline level. -->
  <!ENTITY % misc "script
                   | noscript">
  <!ENTITY % Inline " (#PCDATA
                     | %inline;
                     | %misc; )*">

This declaration fragment builds the final Inline parameter entity in small pieces. Notice that the Inline entity definition contains the inline and misc entities and uses the technique described in Chapter 4 for including an unlimited number of child elements in any order-in this example, using (#PCDATA | %inline; | %misc; )*.

In the example DTD created in Chapters 3 and 4, the p element was used to organize the content within a cell. Although that usage makes sense, the purpose of the p element is to make text that is not included in a block element (such as text within an h element) word-wrap properly. Therefore, putting the h element or any of the block elements within a p element is not necessary because text within a block element is already word-wrapped. On the other hand, if any of the inline elements are used outside of a block element, they should be placed inside a p element so that the text element wraps properly. Therefore, you could rewrite the definition for the p element as follows:

  <!ELEMENT p %Inline;>

This shows exactly the way the definition for the p element appears in the XHTML specification.

Block entities and elements

The XHTML standard also declares a set of internal parameter entities that can be used in the declarations of the block elements. These internal parameter entities appear as follows:

  <!ENTITY % heading "h1
                      | h2
                      | h3
                      | h4
                      | h5
                      | h6">
  <!ENTITY % lists "ul
                    | ol">
  <!ENTITY % blocktext "hr
                        | blockquote">
  <!ENTITY % block "p
                    | %heading;
                    | div
                    | %lists;
                    | %blocktext;
                    | fieldset
                    | table">
  <!ENTITY % Block " (%block;
                    | form
                    | %misc; )*">

Notice that the Block entity contains the block entity, the misc entity, and the form element and also includes an unlimited number of these child elements in any order. Using the Block parameter entity, the declaration for the body element becomes the following:

  <!ELEMENT body %Block;>

As you can see, using the parameter entities, you can give your document a clear structure.

Using parameter entities in attributes

The XHTML standard also uses parameter entities in attributes, as we saw earlier with the events entity. You could use this events entity and two additional entities to create an internal parameter entity for attributes shared among many elements, as shown here:

  <!-- Internationalization attributes
      lang        Language code (backward-compatible)
      xml:lang    Language code (per XML 1.0 spec)
      dir         Direction for weak/neutral text
  <!ENTITY % i18n " lang     NMTOKEN  #IMPLIED
                    xml:lang NMTOKEN  #IMPLIED
                    dir      (ltr | rtl )  #IMPLIED">
  <!ENTITY % coreattrs
                " id      ID       #IMPLIED
                  class   CDATA    #IMPLIED
                  style   CDATA    #IMPLIED
                  title   CDATA    #IMPLIED">
  <!ENTITY % attrs " %coreattrs;

The language entity i18n can be understood by XML and non-XML compliant browsers and is used to mark elements as belonging to a particular language.

For more information about language codes, visit the Web site http://www.oasis-open.org/cover/iso639a.html.

The attrs parameter entity can be used for the most common attributes associated with the HTML elements in the DTD. For example, the body element's attribute can now be written as follows:

  <!ATTLIST body  %attrs;
                  onload   CDATA  #IMPLIED
                  onunload CDATA  #IMPLIED>
by BrainBellupdated