Empty Elements in XHTML

A

August Karlstrom

Hi everyone,

In XHTML, can any empty element <foo></foo> be replaced by <foo />?

Example:

<table>
<tr><td>1</td><td>2</td></tr>
<tr><td /><td>4</td></tr>
</table>


Regards,

August
 
M

Martin Honnen

August said:
In XHTML, can any empty element <foo></foo> be replaced by <foo />?

Example:

<table>
<tr><td>1</td><td>2</td></tr>
<tr><td /><td>4</td></tr>
</table>

If parsed as XML it will not matter whether you have
<td></td>
or
<td />
or
<td/>

On the other hand the XML 1.0 specification says
"For interoperability, the empty-element tag SHOULD be used, and
SHOULD only be used, for elements which are declared EMPTY."
so as td elements are not declared as empty".
That is also what the XHTML 1.0 specification suggests if you want to
serve XHTML 1.0 documents as text/html. In that case you markup an empty
table cell as <td></td> and only elements defined as being empty (such
as the br element) as <br />.
 
A

August Karlstrom

Martin Honnen skrev:
If parsed as XML it will not matter whether you have
<td></td>
or
<td />
or
<td/>

On the other hand the XML 1.0 specification says
"For interoperability, the empty-element tag SHOULD be used, and
SHOULD only be used, for elements which are declared EMPTY."
so as td elements are not declared as empty".
That is also what the XHTML 1.0 specification suggests if you want to
serve XHTML 1.0 documents as text/html. In that case you markup an empty
table cell as <td></td> and only elements defined as being empty (such
as the br element) as <br />.

OK, thanks for the accurate answer.


August
 
A

Andy Dingley

In XHTML, can any empty element <foo></foo> be replaced by <foo />?

What's "XHTML" here?

If you mean "XHTML as XML", then of course they're absolutely
identical. However you can't use XHTML as XML on today's web (an FAQ
in c.i.w.a.h)

if you mean "Appendix C XHTML" so as to make it usable on the web,
then they're different and must be kept distinct. XML sees "empty
elements" as those with no current content at that time. HTML sees
"empty elements" as those defined as empty in ther DTD (e.g. <img>,
<br>, <hr> etc.) These _defined_ empty elements should be serialised
as <br /> but non-empty elements with no content must remain as start
and end tags, e.g. <script src="foo.js" ></script>

There's a huge amount of past discussion of this in c.i.w.a.h, some of
it's even accurate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top