"Hostile17" <hostile17@bigfoot.com> wrote in message
news:c610561.0309111701.35e86935@posting.google.co m...[color=blue]
> Consider the following HTML.
>
> ----------
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
> "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
> <html>
> <head>
> <meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
> <title>Untitled</title>
> <link rel="Stylesheet" href="mystylesheet.css" />
> </head><body>
> <img src="myimage.gif" alt="my image" width="100" height="100" />
> </body>
> </html>
>
> ----------
>
> There's a guy a work who insists on coding like this. Or rather,
> *some* of his images have a trailing slash, not others, and his link
> tags, as above, have them, but not his meta-tags.[/color]
A / at the end of a tag is not valid with any 4.01 DTD. Your guy is wrong.
Go to the spec -
http://www.w3.org/TR/html4/ - and have a look.
The fact that it appears to "work" is that the browsers error correction is
kicking in and throwing away the invalid '/' attribute.
[color=blue]
> I don't know where he picked up the habit, but he says it's valid 4.01
> Transitional, and it's also "best practice".[/color]
No it is not. It is an XHTML rule that empty elements be closed, most easily
by including the closing, the /, in the opening tag. This is actually a
requirement of XML. It has nothing to do with HTML.
[color=blue]
> If it is, why aren't all his single tags like this, but let's move on.[/color]
Because he is only wrong some of the time :-)
[color=blue]
> In an attempt to get an official answer on this, I validate the above
> at the W3C.
>
> I get this result:
>
> ----------
>
> Line 7, column 6: end tag for element "HEAD" which is not open
> (explain...).
>
> Line 8, column 5: document type does not allow element "BODY" here
> (explain...).[/color]
The validator's error recovery is not quite as good as the browsers. It is
misinterpreting /> as something else and getting screwed up a bit further
down.
Probably it is interpreting something in the head as body text. This is
quite permissable, a UA should implicitly close the head element and open a
body element. You get exactly the same effect if you use something like
<p>text</p> inside your head element.
So, when the validator gets to the </head> tag it raises an error. The head
element has already been closed. When it gets to the <body> tag it raises an
error. The body element has already been opened. You can not have nested
body elements.
[color=blue]
> ----------
>
> If I validate it with BBEdit's built-in Check Syntax, it give me this:
>
> ----------
>
> File "xmlstyle.html"; Line 7: Document type doesn't permit empty XML
> element; "<link/>".
> File "xmlstyle.html"; Line 10: Document type doesn't permit empty XML
> element; "<img/>".
>
> ----------
>
> When I show these results to the coder, he says the W3C is complaining
> about "HEAD and BODY tags on the same line" which is laughable,[/color]
Very true. See above.
[color=blue]
> but
> he's got a point when he says "BBEdit says the tags are empty. They're
> not empty."[/color]
Look again. It does not say empty tag, it says empty element. The image and
link elements are indeed empty elements, they have no content like that
title element up there does. All the goodies with a link or image element
happen in the opening tag.
With HTML empty elements do not have a closing tag. So, if you attempt to
close the element in the opening tag BBEdit, correctly, gets upset. It would
also get upset if you said something like <img...>description of
image</img>. It's just not allowed.
[color=blue]
> I could go on trying other validators, but I'm not happy with the
> results of these.[/color]
Don't bother. Use the specs.
[color=blue]
> Validated as 4.01 Strict, by the way, these tags are definitely
> errors. "Character Data Is Not Allowed Here" with an arrow pointing to
> the end of the tag.[/color]
Correct. Transitional allows invalid attributes (the /). Strict does not.
You want a new attribute? Add it to the DTD.
[color=blue]
> What I want is someone to give me a definitive response, backed up by
> a link to a reputable website, where it gives an answer either way. I
> think I'm right but I can't cite anything.[/color]
As I said, go to the spece above. Also look up the XHTML spec. There is a
good description of what is new/different with XHTML and the above is
specifically mentioned.
Cheers
Richard.