Re: I would like to point this out

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 UTC