Jump to content

Html Not X(ht)ml


Guest FirefoxRocks

Recommended Posts

Guest FirefoxRocks

Is it possible for me to implement some sort of draconian error handling in HTML without using XHTML or XML?The reason for not using XHTML is because Internet Explorer doesn't handle application/xhtml+xml and XML is not really appropriate I guess.I can use PHP and JavaScript (not ASP or anything like that). Basically the only elements that do not need closing tags are empty elements (img, br, hr, col, link, meta, ...). I also require all attribute values to be quoted. Basically if it finds anything without a closing tag (or improperly nested) or unquoted attribute values (even if it only contains alphanumeric characters, hyphens and/or periods), I need an error message displayed and the entire page to break.I can also use any version of HTML for this as long as I can achieve the desired result.

Link to comment
Share on other sites

Output buffer everything and check the W3C validator at the end? But why do you want to do this in the first place - end users should not be exposed to errors if you can help it.

Link to comment
Share on other sites

Why not output XHTML? You can output it even with the HTML MIME type, and it will render perfectly fine. With PHP, you can do content negotiation so that you can give proper XHTML only to browsers that support it, and text/html to the rest.

Link to comment
Share on other sites

Guest FirefoxRocks
Output buffer everything and check the W3C validator at the end? But why do you want to do this in the first place - end users should not be exposed to errors if you can help it.
How do I check the W3C validator at the end?
Why not output XHTML? You can output it even with the HTML MIME type, and it will render perfectly fine. With PHP, you can do content negotiation so that you can give proper XHTML only to browsers that support it, and text/html to the rest.
If I output it with the HTML MIME type, browsers will not do draconian error handling. I need draconian error handling in all major browsers, which includes Internet Explorer 7 and 8.
Link to comment
Share on other sites

How do I check the W3C validator at the end?If I output it with the HTML MIME type, browsers will not do draconian error handling. I need draconian error handling in all major browsers, which includes Internet Explorer 7 and 8.
OK, fine... but be warned that this way is going to make each and every one of your pages REALLY slow. Imagine running the validator over every page, before it actually starts to render... yeah... THAT slow.
<?phpob_implicit_flush(false);ob_start();//PHP script here$dom = new DOMDocument;$dom->validateOnParse = true;if (!$dom->loadXML(ob_get_contents())) {	//Error handling here... use the libxml (http://bg2.php.net/manual/en/book.libxml.php) functions to get the actual error}else {	ob_flush();	flush();}?>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...