W3C home > Mailing lists > Public > www-validator@w3.org > October 2001

Re: I would like to point this out

From: Nick Kew <nick@webthing.com>
Date: Fri, 26 Oct 2001 15:51:34 +0100 (BST)
To: David Wright <dwright5@nyc.rr.com>
cc: <www-validator@w3.org>
Message-ID: <20011026152528.O622-100000@fenris.webthing.com>

On Thu, 25 Oct 2001, Bjoern Hoehrmann wrote:

> >   2: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> >   3:         "http://www.w3.org/TR/html4/loose.dtd">
>
> HTML 4 selected

It occurs to me that herein lies a nice illustration of the benefit
of selecting a stricter DTD.  Allowing as much slack as loose.dtd
(or even strict.dtd) leads to misleading error messages.

> >  18: <link rel="stylesheet" type="text/css" href="css/external.css" />
> >  19: </head>
>
> Note the trailing />, this is interpreted as
>
>   <link ...>&lt;
>   </head>
>
> in HTML 4. PCDATA is not allowed in <head>, so <head> is closed and
> <body> is opened, validator finds </head> and you get

Under loose.dtd you get that.

With strict.dtd, PCDATA isn't allowed in <BODY> either, so you'd get
a less misleading error message at line 18.  And since it doesn't
parse correctly with an inferred </head><body>, it won't generate
a cascade of misleading (dare I say bogus?) error messages.

With a slightly tidied DTD that requires the </head> and <body>
(and - for similar reasons - other elements) explicitly, the parsing,
and hence the error messages, are much rationalised.  See for instance
<URL:http://www.htmlhelp.org/design/dtd/>.

> >the error i receive is
> >  </head>
> >        ^
> >
> >Error: end tag for element "HEAD" which is not open; try removing the end
> >tag or check for improper nesting of elements

Oh dear ...

> Now it finds <body> while already inside <body> and you get
>
> >*    Line 21, column 5:
> >
> >  <body>
> >       ^
> >
> >Error: element "BODY" not allowed here; check which elements this element
> >may be contained within

QED?

-- 
Nick Kew

Site Valet - the essential service for anyone with a website.
<URL:http://valet.webthing.com/>
Received on Friday, 26 October 2001 17:39:50 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:00 GMT