Hi.
(this is somewhat similar to yesterday's thread about empty links)
I noticed that Tidy [0] issues warnings whenever it encounters empty
tags, and strips those tags if cleanup was requested. This is okay in
some cases (such as <tbody>), but problematic for other tags (such as
<option>). Some tags (td, th, ...) do not produce warnings when they are
empty.
The warnings are also issued for documents that are considered valid
"XHTML 1.0 Strict" by the W3C Validator. If any of these empty-tag
warnings were issued, Tidy recommends "XMTML 1.0 Transitional" instead.
A few examples:
1) empty <select> options
-----------------------------------------------------------------
<select name="x">
<option value=""></option>
<option value="foo">a foo</option>
<option value="bar">a bar</option>
</select>
[tidy] Warning: "trimming empty <option>"
I don't know how I could avoid this warning. I don't want to display any
text in the first option, and hacks like <option> </option> are not
acceptable.
2) Empty p, div, span, h1, a[href], ... tags
-----------------------------------------------------------------
<td class="c1"><span class="c2"></span> Some Text</td>
Constructs like this are sometimes used by our webdesigner in
combination with CSS. The span tag is technically empty, but the
stylesheet will cause an image to be displayed.
<div id="ibox"></div>
This could happen for example if "ibox" was a box containing additional
information for the main content, but there are no additional infos the
current page. The box itself should still be displayed, so the tag is
left empty.
<p class="notes"><?= $notes ?></p>
Empty tags can also occur as an artifact of server-side scripting; if
$notes is empty, so is the <p> tag (this case can be avoided, I know).
3) Empty td, th tags; script tags
-----------------------------------------------------------------
<tr><th></th></tr>
<tr><td></td></tr>
Tidy ignores empty table cells and does not try to strip them.
<script type="text/javascript" src="xxx.js"></script>
Same goes for empty script tags with src attributes.
4) Empty thead, tfoot tags
-----------------------------------------------------------------
<table>
<thead><tr><td>head</td></tr></thead>
<tfoot></tfoot>
<tbody><tr><td>body</td></tr></tbody>
</table>
Tidy issues a warning for the empty tfoot element, which is expected
because <tfoot> must never be empty. In this case I would actually
rather get an error instead of a warning, because the document does not
qualify as valid XHTML anymore.
I would like to get rid of the warnings in 1) + 2), to simplify
automated validation and to ease my mind. Is Tidy correct in issuing
warnings and stripping the tags? Should I always try to avoid empty
tags? If so, how?
Thanks in advance,
Stefan
[0] http://tidy.sourceforge.net/