views:

34

answers:

1

I am trying to validate the following code with the W3C validator:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>Test</title>
</head>
<body>
</body>
</html>

I get two errors:

Document type does not allow element "body" here

End tag for "html" which is not finished

Does anyone know how to fix this?

+4  A: 

You're using the Frameset DTD, which doesn't allow body. It is meant for use with framesets, which are used to display frames. You can use Strict instead:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>Test</title>
</head>
<body>
</body>
</html>
Matthew Flaschen
But then I can't use frames
Casebash
Doctype decorations :)
Thqr
@Thqr: What do you mean?
Casebash
Its what I call the arguement for using different doctype declarations "Doctype Decorations" someone will always say to use a different one (usually). But depends what frames are you using?
Thqr
You want either a frameset or a body element in each page, but not both. Your `<frame>`s should have as attributes references to other (X)HTML files which in turn should be either framesets or simple pages without frames.
Ben Alpert
@Case, yes, you can't have both a body and a frameset, unless the body is in a noframes.
Matthew Flaschen
@Ben: Framesets appear to only allow you to have frames at the top level of a document. I am currently using an iframe pretty deep inside the document to display an error message page (which can be arbitrary html) in an expandable section. I think I may switch to using Transitional instead.
Casebash
Basically, each file should have exactly one of either a `<frameset>` or a `<body>`. If you used a `<frameset>`, then use the Frameset DOCTYPE. Otherwise, use Strict or Traditional.
Ben Alpert
@Ben Alpert - There is no need for transitional on new web pages.
Rob
@Rob: Unless you need things like iframes
Casebash
@Casebash - iframes are standard HTML and work just fine with strict.
Rob
@Rob: Strict XHTML gives me a validation error
Casebash
@Casebash - I didn't notice he was using XHTML which doesn't support iframe since it's XML.
Rob