Log in

View Full Version : SSI errors on W3C validator



questions
01-25-2008, 06:27 AM
I'm new to this SSI but basically I've done really simple tries by the book, as it were, and they come out looking right. But when I test them here:

http://validator.w3.org/

There are errors related to the fact that the "DOCTYPE" from the original (or included) html is showing up in the "script".


Example of what this script looks like before (when I wrote it):

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<!--#include virtual="/ssi-test/css-in.html" -->
</body>
</html>


And when processed and read through the web:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>


<style type="text/css">

.bigfont {
font-family: Arial, Helvetica, sans-serif;
font-size: 36px;
font-style: normal;
font-weight: bold;
text-decoration: line-through;
}

table {background: #9999CC
}
body {
background-color: #FFFF33;
}
</style>


</head>

<body>

<p class="bigfont">I WENT RUNNIN THROUGH THE FOREST</p>
<p>I WENT RUNNIN THROUGH THE FOREST</p>


<table width="717" height="251" border="0" cellpadding="0" cellspacing="5">
<tr>

<td>&nbsp;</td>
</tr>
</table>

</body>
</html>

</body>
</html>




Error 1 example:

Line 9, Column 2: "DOCTYPE" declaration not allowed in instance .

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or



Error 2 example:
Line 10, Column 42: document type does not allow element "html" here .

<html xmlns="http://www.w3.org/1999/xhtml">



The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).


Sorry this is so long.
Does anyone know what this is about?

Thanks much!

BLiZZaRD
01-25-2008, 06:31 AM
Your include page already has full headers and everything



<!--#include virtual="/ssi-test/css-in.html" -->


This page.

So you either need to a) remove ALL headers, titles, html and body tags OR b) don't put them on the page with the include. (i.e. just a blank page with only the include statement in it.

questions
01-25-2008, 06:35 AM
Really? I thought all pages have to have the DOCtype and head and body tags on them. You are saying I can leave some out? On either page? Would it still work? I will give it a try.

jscheuer1
01-25-2008, 06:40 AM
All pages should have those things, but unless your includes are stand-alone pages, they do not need them as long as the pages that they are going to be included on have them. Remember, it is the served code as a whole that should validate as a page, not the resources that contribute to it.

questions
01-25-2008, 06:47 AM
You guys rock! I finally got it... I really looked everywhere for an answer to this but I think it seems so obvious to everyone that no one discusses it.

So, what I've done is leave all the head and body and html tags in the .shtml file and in the include file took that out... because I might want to include 2 or more files and so none of them should have that information in them.

I was confused a while with where to put the CSS info, but that also needs to go into the .shtml file that has all the includes stuck into it because it's "header" info.

Thanks a lot!!!!!!!!!!! I am new to all of this (well, the correct and simple way of doing things...)

Twey
01-25-2008, 07:06 AM
You probably want this DOCTYPE:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">Transitional DOCTYPEs are outdated, and XHTML isn't properly supported yet.

questions
01-28-2008, 07:20 AM
Huh. I read on someones tutorial page to put XHTML Strict down. The DOCTYPE I got is from Dreamweaver CS3... you'd think that would be up to date. So I just left it as the Dreamweaver.

What do you mean by outdated?

I thought the order goes from HTML to XHTML.

Twey
01-28-2008, 07:26 AM
What do you mean by outdated?The "transitional" period from HTML3 to HTML4, for which that DOCTYPE (well, actually the HTML version; the XHTML is a direct translation of that to XML) was designed, was about ten years ago. Now, designers use it just to excuse sloppy code.
I read on someones tutorial page to put XHTML Strict down.Then whoever wrote that tutorial was a) wrong, b) intentionally misleading, or c) misunderstood by you (mm, dodgy use of passive voice). XHTML is newer than HTML by about one month. It's a parallel standard, and does not obsolete HTML. More importantly for our purposes, IE is currently completely unable to render it. See: http://www.webdevout.net/articles/beware-of-xhtml
The DOCTYPE I got is from Dreamweaver CS3... you'd think that would be up to date.Considering the abysmal quality of code that Dreamweaver spouts, I would expect nothing of the sort.

questions
01-28-2008, 07:37 AM
Thanks. Learning so much...

questions
01-28-2008, 07:45 AM
It seems that for my basic purposes of putting together a simple web page, there is no difference between XHTML & HTML, as the tags, attributes, etc. are the same. It's just the declaration of DOCTYPE that I need to change.

Twey
01-28-2008, 08:57 AM
Also the content type. HTML needs to be served with the text/html Content-Type header, while XHTML has to be served as application/xhtml+xml. Also, the <foo /> self-closing tag syntax is invalid in HTML (well, technically not invalid, but it's an obscure SGML feature that no browsers support any more, which, if it were rendered correctly, would cause <foo /> to be exactly equivalent to <foo>&gt;), and some tags therefore require explicit ending tags (e.g. <script type="text/javascript" src="foo.js" /> is valid XHTML, but if written in HTML will cause the tag to remain unclosed and everything from there onwards to be treated as if it were part of the script, and thus ignored).

BLiZZaRD
01-28-2008, 09:41 PM
One thing I love about the validators is they will catch any nuance of tag being sandwiched wrong H tag outside a P tag, etc.. but I can open a <p> and never close it and this is fine.. funny.

jscheuer1
01-29-2008, 03:29 AM
One thing I love about the validators is they will catch any nuance of tag being sandwiched wrong H tag outside a P tag, etc.. but I can open a <p> and never close it and this is fine.. funny.

This is something that has bothered me off and on whenever I encounter it, which generally is in the way style is interpreted by a browser, not what the validator says. For instance (in a standards compliant browser):


<style type="text/css">
#cont p {
color:yellow;
}
#cont p p {
font-weight:bold;
}
</style>


<div id="cont"><p>Some Text<p>Other Text</p></p></div>

You would expect 'Other Text' to be bold, but it is not. If you had:


<style type="text/css">
#cont div {
color:yellow;
}
#cont div div {
font-weight:bold;
}
</style>

and:


<div id="cont"><div>Some Text<div>Other Text</div></div></div>

it would be bold. This, and what you mention BLiZ, leads me to believe that <p> is a somewhat automatically self closing tag.

I've also noticed 'problems' with p in scripts when writing out HTML code.

Bottom line, the p tag seems to close at the earliest possible opportunity, and any </p> tokens that occur after that are ignored if the opening <p> has already 'self closed'.

<p> also has different default layout in IE than in other browsers. It's the default margins that vary, I think. For these reasons, I'm considering abandoning it entirely.

BLiZZaRD
01-29-2008, 03:34 AM
I agree John, I just haven't found a validating, reasonable variance to use that can capture what a well used <p> tag can do. I do despise the margin differences in IE though.. throws me for a loop every time I test a new page.

questions
01-29-2008, 03:52 AM
Also the content type. HTML needs to be served with the text/html Content-Type header, while XHTML has to be served as application/xhtml+xml. Also, the <foo /> self-closing tag syntax is invalid in HTML (well, technically not invalid, but it's an obscure SGML feature that no browsers support any more, which, if it were rendered correctly, would cause <foo /> to be exactly equivalent to <foo>&gt;), and some tags therefore require explicit ending tags (e.g. <script type="text/javascript" src="foo.js" /> is valid XHTML, but if written in HTML will cause the tag to remain unclosed and everything from there onwards to be treated as if it were part of the script, and thus ignored).

So <br> is still like this?
And you are "guaranteeing" that we will not need to switch to <br /> in the near future...

BLiZZaRD
01-29-2008, 03:56 AM
only if you are using a php echo statement or using X/HTML. HTML 4.01 strict valid code will throw a warning. But the <br> by itself isn't valid either, it must be in a container element like a <p> or a <div>.

questions
01-29-2008, 05:14 AM
OK. I guess when the time comes to replace <br> with <br /> I can just run a "find and replace," like in word or something.

Twey
01-29-2008, 11:14 AM
it would be bold. This, and what you mention BLiZ, leads me to believe that <p> is a somewhat automatically self closing tag.Paragraphs are not really self-closing, but it is illegal (and impossible) to nest them. Thus, if the parser finds an opening <p> tag whilst it is still inside a <p> tag, it should consider the first <p> closed before opening the second.
<p>foo<p>bar</p></p>is thus invalid, because there are two </p> closing tags, but only one <p> open.
I do despise the margin differences in IE though.. throws me for a loop every time I test a new page.Thus, I always use a rule such as:
* {
padding: 0;
margin: 0;
}... at the start of my stylesheet to remove these differences.
So <br> is still like this?
And you are "guaranteeing" that we will not need to switch to <br /> in the near future...Yes. You won't have to switch to XHTML until at least XHTML 2 or XHTML 5, both of which require a more substantial page rewrite than simply adding in self-closing tags.

questions
01-30-2008, 06:42 AM
Yes. You won't have to switch to XHTML until at least XHTML 2 or XHTML 5, both of which require a more substantial page rewrite than simply adding in self-closing tags.

Great... more substantial rewrites... I look forward to that... Maybe by then I can just hire someone to do it for me :)