Why does this html table definition not validate?
Asked Answered
C

4

5

I'm getting this W3C HTML validation error:

end tag for "table" which is not finished

for this code:

<table id="myTable">
</table>

This is my DOCTYPE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

I thought that table definition was perfectly fine!?

Corot answered 30/11, 2010 at 19:23 Comment(1)
It looks OK to me. Is this the actual code that is throwing the error?Kary
D
6

If you look at the XHTML 1.0 Strict DTD, it specifies that a table requires at least one of TR OR TBODY:

<!ELEMENT table
     (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))>
<!ELEMENT caption  %Inline;>
<!ELEMENT thead    (tr)+>
<!ELEMENT tfoot    (tr)+>
<!ELEMENT tbody    (tr)+>
<!ELEMENT colgroup (col)*>
<!ELEMENT col      EMPTY>
<!ELEMENT tr       (th|td)+>
<!ELEMENT th       %Flow;>
<!ELEMENT td       %Flow;>

The TR, in its turn, requires at least one of TH or TD.

The + sign after an element name means it should appear at least once.

Delindadelineate answered 30/11, 2010 at 19:29 Comment(6)
I was looking for that in the spec, and you beat me to it.Reify
The OP's document doesn't use HTML 4.0.Omnipotent
@Matthew Flaschen XHTML 1 and HTML 4 use the same basic specs, I'll have to go look in the XHTML 1 DTD, but the only real difference is some syntax specifications in XHTML.Reify
@Matthew Flaschen - fair point. Answer updated for XHTML 1.0 DTD.Delindadelineate
Same basic thing: w3.org/TR/2000/REC-xhtml1-20000126/DTD/xhtml1-strict.dtd search for <!ELEMENT table just like in the HTML4 version. at least one tbody and tr are required.Reify
@Reify - indeed. Matthew was right however, so I updated my answer.Delindadelineate
A
3

I believe there should be a tr and td tags inside a table to validate. It's the same when you close a head tag without including a title tag

Antechoir answered 30/11, 2010 at 19:25 Comment(1)
I'm not getting this warning when I do <table></table>Pokelogan
O
3

A XHTML 1.0 table is required to have at least a tbody or a tr child. See the DTD, specifically the table element:

<!ELEMENT table
     (caption?, (col*|colgroup*), thead?, tfoot?, (tbody+|tr+))>

Note the last part.

Omnipotent answered 30/11, 2010 at 19:28 Comment(0)
G
0

Take a look at http://validator.w3.org/docs/errors.html

73: end tag for X which is not finished

Most likely, you nested tags and closed them in the wrong order. For example <p><em>. </p> is not acceptable, as <em> must be closed before <p>. Acceptable nesting is:

<p><em>...</em></p>

Another possibility is that you used an element which requires a child element that you did not include. Hence the parent element is "not finished", not complete. For instance, in HTML the element must contain a child element, lists require appropriate list items (<ul> and <ol> require <li>; <dl> requires <dt> and <dd>), and so on.

You need at least one <tr> inside your table.

Gilligan answered 30/11, 2010 at 19:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.