We host MSHTML in out application and use MSHTML in edit mode as a text editor. I came across a situation where after editing, the DOM returned by MSHTML looks spooky. Let me give an example. We start with (simplified HTML)
<BODY><P>Hello World</P></BODY>
The user then clicks at the end of the text, presses ENTER twice and writes some text. The HTML in the control now is:
<BODY><P>Hello World</P><P><BR></P><P>Hello Microsoft</P></BODY>
This is all right, except if I try to access the contents of the second P node. I will get a paragraph node as expected, but when I try to examine the children, it thinks thereare no children. Casting this to IHTMLDOMNode and trying this way yields no result either – MSHTML insists that the P element has no children. However, asking it for outerHTML, it returns “<P><BR></P>” – which is spooky, at there clearly is a BR tag inside the P tag, so I would expect to find aBR child element. Saving to disk and reloading the HTML will change the picture andP will have a child as expected. Only when live editing will this awkwardness occur.
Can you tell me wht the BR element is question is missing from the DOM node tree and what I can do to force MSHTML to update its DOM tree and make the BR element accessible from code.