My understanding is that XHTML is based on XML, which has strict parsing rules. Inserting content into a document with document.write() is a big "NO NO" as XML parsers are not designed to handle it.
You can, of course, disable the message or "tone it down" to a warning using CSE HTML Validator's configuration options.
Or, better yet may be to change the document to HTML5 if you don't need XML parsing.
No. Because of the way XML is defined, it is not possible to do tricks like this, where markup is generated by scripting while the parser is still parsing the markup.
You can still achieve the same effects, but you have to do it by using the DOM to add and delete elements.
I will improve the message to give more details about this issue.
When an XHTML page is served with MIME type text/html it is treated by all browsers as if it were nothing more than HTML. However when an XHTML page is served with MIME type text/xml or application/xhtml+xml, then it should be treated as an XML document which must conform to the strict rules for authoring and displaying XML.
My pages are text/html via the content-type and also via server headers.
I see your point, but I'm not sure what the best solution is. If a browser treats an XHTML document as HTML, then document.write() should work, but the underlying document is still an XHTML document (or should be) even though the browser may not treat it as such.
I think the best solution may be to leave it as an error and let the developer "tone it down to a warning or regular message" or ignore it completely if they want.
It may also be possible to check the MIME type (if the document was requested with HTTP), and if it's available and if it's text/html, then CSE HTML Validator could handle it a bit more leniently (perhaps a warning instead - and change the message ID so the message could be disabled independently from when this is not the case).
Thanks Rick. I'll just leave it as is for now. I did try to make the message more informative though:
Because of the way XML is defined and parsed, XHTML documents should not use document.write() or document.writeln(), but it appears that this has been used in this script. XML (and therefore XHTML) does not allow for markup to be generated while the parser is still parsing the markup. To add and delete elements, use the DOM and innerHTML property instead.