Sp 64

From Htmlpedia
Jump to: navigation, search

OpenSP: Document type does not allow element %1 here

Cause:

The element named above was found in a context where it is not allowed by the DOCTYPE Declaration.

This usually means that you have put a legitimate element someplace it shouldn't be -- such as a "style" element in the "body" section instead of inside "head".

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).

If you are using JavaScript to insert HTML into a document on the client-side, you need to hide the HTML elements in your JavaScript from the validator. This is especially true if you are working with XHTML.

Examples

Improperly placed STYLE element:

Bad
<!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" lang="en" xml:lang="en">
<head>
	<title>Stylin'</title>
</head>
<body>
	<style type="text/css">
	</style>
</body>
</html>
Good
<!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" lang="en" xml:lang="en">
<head>
	<title>Stylin'</title>
	<style type="text/css">
	</style>
</head>
<body>
</body>
</html>

XHTML syntax in an HTML document:

Bad<link ... />
Good<link ... >

Un-escaped JavaScript in an XHTML document:

Bad
<script type="text/javascript">
var output = "<html><body><p>Hi!<\/p><\/body><\/html>";
</script>
Good
<script type="text/javascript">
//<![CDATA[
var output = "<html><body><p>Hi!<\/p><\/body><\/html>";
//]]>
</script>

Solution:

  • If the problem is caused by a mis-placed element, move it.
  • If the problem is caused by using XHTML syntax in an HTML document, then remove the trailing slashes.
  • If the problem is caused by HTML within a JavaScript, then escape the JavaScript by marking it as CDATA.

References: