firefoxxhtmldoctype

"Stray doctype" error in firefox source code viewer


Since I learned to serve XHTML pages as XML, I have started noticing something odd: whenever I view an XHTML page in the Firefox source code viewer, the DOCTYPE is always marked as an error. According to the tooltip I get from mousing over it, the error in question is a "stray doctype". From what I understand, a "stray doctype" means that there is an extra DOCTYPE in the middle of the document where it doesn't belong, which is certainly not the case here.

Here's an example - this markup will pass validation, and display correctly in all modern browsers:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--FF source viewer will mark the preceding two lines as an error.-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
    <meta http-equiv="content-type"
      content="application/xhtml+xml; charset=utf-8" />
    <title>Sample XHTML Page</title>
  </head>
  <body>
    <p>This is an example.</p>
  </body>
</html>

This error message is especially odd, considering that these pages pass validation perfectly, and that a single parsing error would normally break the page.


Solution

  • I am the developer of this feature. You have found a bug. (Filed just now.) Thanks.

    View Source syntax highlighting is based on the HTML parser, because our XML parser is not suited for the purpose and XML is rare enough that it doesn't make sense to put resources into implementing proper XML View Source. Hence, the XML View Source feature is a hack on the HTML parser and this aspect doesn't work quite right.