First two bytes of a file

I've noticed what might be classified as an error in the www validator
(http://validator.w3.org/). I discovered this when trying to validate
a page for XHTML and CSS standard conformance. The page returned valid
XHTML, but the jigsaw CSS validator
(http://jigsaw.w3.org/css-validator/validator-uri.html)
said otherwise. When validating a page for valid CSS, I think the
jigsaw validator checks the first two bytes of the file for the file
type definition (which will be "<?" in the case of valid XML). I
noticed that my perl code which was generating the offending  XHTML
was inserting three newlines instead of two after the "Content-type:"
declaration. The third newline was then being included in the file,
and threw the CSS validator off, but not the XHTML validator.

Perhaps the XHTML validator should provide a warning if it discovers
this situation? I'm not quite sure how serious an issue it is.

I've provided two perl scripts which may help illustrate this better.
You may need to provide a "default.css" file though.

--BEGIN PERL CODE--

#!/usr/bin/perl -w

#please note that the total number of newlines in the following first two lines is three

print qq|Content-type: text/html\n\n
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title>No CSS Validation</title>
	<link rel="StyleSheet" href="default.css" type="text/css"
		title=default media="screen" />
</head>
<body><p>The Jigsaw CSS validator will refuse to validate the generated
XHTML, due to "bad" XHTML, even though the XHTML validator reports conformance.</p></body>
</html>|;

--END PERL CODE--


--BEGIN PERL CODE--

#!/usr/bin/perl -w

#now we have just two newlines...

print qq|Content-type: text/html

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title>No CSS Validation</title>
	<link rel="StyleSheet" href="default.css" type="text/css"
		title=default media="screen" />
</head>
<body><p>Both the Jigsaw CSS validator and the XHTML validator report conformance.</p></body>
</html>|;

--END PERL CODE--

Thanks for reading,

Dave Edwards.

Received on Saturday, 22 November 2003 14:05:30 UTC