HTML and CSS Reference
In-Depth Information
Whitespace Handling
Leading and trailing whitespace characters are stripped in XHTML. In contrast to HTML, whitespace characters in
XHTML attribute values are normalized to single spaces. According to the XML specification, a single interword
space ( #x20 ) is appended to whitespace character sequences ( #x20 , #xD , #xA , #x9 ) [32].
Using Script and Style Elements
While the content type of the script and style HTML elements is character data (CDATA), it is processed character
data (#PCDATA) in XHTML. The script and style elements are defined with #PCDATA content; in other words, < is
handled as the beginning of markup code, while &lt; is recognized as an entity (Listing 3-23).
Listing 3-23. Unescaped Script Content to Display x<y in XHTML through Javascript
<script type="text/javascript">
unescaped script content x&lt;y
XML processors recognize these CDATA sections, and display the content rather than processing it as XML. If
there is no script content to unescape, the <![CDATA[ and ]]> lines would be omitted, which is identical to the usual
script embedding in HTML. The CDATA sections are represented as nodes in the Document Object Model.
The unescaped script or style contents are not needed in external script files and styles sheet files.
Instead of the name attribute defined in HTML 4, the id attribute should be used in XHTML for identifiers. XHTML
documents must use the id attribute when defining fragment identifiers on the a , applet , form , frame , iframe , img ,
and map elements. This ensures the well-structuredness required by XML.
Element Prohibitions
In XHTML, elements cannot be nested arbitrarily. Those who are not familiar with XHTML often commit nesting
errors. The nesting rules should not be confused with overlapping, which is strictly forbidden in XHTML. The nesting
rules of XHTML 1.0 are similar to those of HTML 4.01, but there are some differences. The table element can contain
a direct tr child element in XHTML, which is not allowed in HTML. In such cases, a tbody element is implied in
HTML but not in XHTML. This behavior is important when tbody is used as a CSS selector. Table 3-4 summarizes
those parent-child element relationships that are not allowed in XHTML.
Table 3-4. XHTML Elements with Prohibitions
Cannot contain other a elements
Cannot contain img , object , big , small , sub , or sup elements
Cannot contain input , select , textarea , label , button , form , fieldset , iframe , or isindex elements
Cannot contain other label elements
Cannot contain other form elements
Search WWH ::

Custom Search