Frequently Asked Questions

When I load some HTML into the editor, I get an error trying to use the DOM

The HtmlEditor wraps Mshtml, which loads documents asynchronously. When you load an HTML document, your code continues to run while the HtmlEditor parses and renders the document. If you immediately try to navigate the Document Object Model (DOM) for the document you just loaded, it won't work because it is not yet ready.

The solution is to wait for the ReadyState property to go to “complete”. There are several ways to do this. The quick-and-dirty way is to poll the control in a loop until it changes. A better idea is to respond to the ReadyStateChanged event. The control fires this event whenever the ReadyState changes, so you can have some code that looks for the value “complete” and then continues processing the document.

The HTMLEditor changes my HTML code and breaks XHTML compatibility

Yes. This is Mshtml - it reformats your code, replaces html entities with characters, converts tags to upper case, removes certain closing tags, and probably other bad things. The official answer is that Mshtml does not support code preservation. There is another Mshtml-based control that *does* have this feature, dhtmled.ocx, but this is deprecated although still part of Internet Explorer. It might be possible to amend the HTMLEditor to use this - look up ITriEditDocument in MSDN - if source preservation is essential.

What most developers do instead is to post-process the HTML. Fortunately there are a number of libraries out there which do this. Chris Lovett's SgmlReader is one example in pure .NET code. Another idea is HtmlTidy originally by Dave Raggett. This doesn't give code preservation exactly, but it does enable applications to exploit Mshtml and still end up with high quality HTML or XHTML code.

 
frequently_asked_questions.txt · Last modified: 2007/09/11 07:54 by 219.142.182.64
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki