posted on Wednesday, February 16, 2005 12:46 PM
by
Andrew Scott
HTML - XHTML
When using contentEditable="true" on an object to enable a user to generate ther own HTML IE generates invalid XHTML.
For example :
<IMG src=image.gif border=0>
This should be :
<img src="image.gif" border="0"/>
Note the case, quotes and the closing tag. Even if the HTML used with pasteHTML() is well formed it generates HTML like the first example. I spend the best part of today trying to write a Regular Expression in javascript to convert it with no luck. Until I gaveup and tried to do it with C# and read HTML to XHTML Conversion with SGMLReader article by Peter Bromberg. Its a Helper / Wrapper class for Chris Lovett of Microsoft's SGMLReader.
With this Wrapper you can parse the HTML back to the server and process it to regerate fully valid XHTML. Once you have done this you can use System.XML to manipulate the document just as if it was always XHTML.