How to Have XHTML Elements Skip Validation
XHTML validation works for developers as a debugging tool and future-proof quality check; helps ease maintenance; and teaches good practices, according to the World Wide Web Consortium, or W3C. Producing 100 percent-compliant XHTML is sometimes an unattainable goal, especially when you must include HTML code snippets from other websites, such as those for traffic counters or Facebook feature integration. If a client requires XHTML validation -- or if you want to get nonstandard or invalid XHTML to pass through a validation service for your personal satisfaction -- you'll find techniques to help.
Instructions
-
-
1
Insert invalid XHTML using conditional comments. Insert the offending XHTML using Internet Explorer conditional comments.
<!--[if IE]>
Place invalid XHTML for IE here
<![endif]-->
-
2
Insert XHTML using JavaScript to hide it from the validator. Insert non-compliant XHTML code using the JavaScript "document.write" command or one of the HTML insertion techniques that JavaScript libraries, such as jQuery or MooTools, offer.
<script type="text/javascript">
document.write('<p>Place invalid XHTML here</p>');
</script>
-
-
3
Create a custom DTD to force validation. Write your own custom XHTML document type definition -- DTD -- or extend an existing doctype to fit your needs. Add the non-compliant XHTML into the file's DTD to force the XHTML validator to recognize the non-standard code.
-
1
Tips & Warnings
These techniques have shortcomings. Only Internet Explorer parses IE conditional comments; all other browsers (and the XHTML validation service) ignore them as regular XHTML comments. Many users browse the Internet with JavaScript turned off, so the JavaScript insertion technique fails for them. Only advanced users should attempt writing custom DTD.
You can get a Web page to work without producing 100-percent compliant, machine-validated XHTML.
References
- Photo Credit Hemera Technologies/PhotoObjects.net/Getty Images Comstock/Comstock/Getty Images