It is not the total solution to your problem, but if you are running PHP5 and have control of the server it is hosted on then you can use the Tidy (HTMLTidy) extension to clean up any user-input (e.g.: filling in missing tags, changing all tags to lowercase, fixing order of tags, adding ending slashes to certain tags, etc.).
I have't tried it yet myself, but plan to do some testing in the near future. It claims to be able to make any block of HTML XHTML/XML compliant.