I'm using axWebBrowser control and HTML DOM in a VB .NET Windows application
to create a new HTML document by cloning nodes. The function below is
called from the axWebBrowser1_DocumentComplete event using:
Dim mNewDoc As mshtml.IHTMLDocument3
mNewDoc = NewDoc(axWebBrowser1.Document)
Private Function NewDoc(ByVal mInputDoc As mshtml.IHTMLDocument3) As
mshtml.IHTMLDocument3
Dim mNodes As mshtml.IHTMLDOMChildrenCollection
Dim mNode, mNewNode As mshtml.IHTMLDOMNode
Dim i As Integer
NewDoc = New mshtml.HTMLDocument
mNodes = mInputDoc.childNodes
For i = 0 To mNodes.length - 1
mNode = mNodes.item(i)
mNewNode = mNode.cloneNode(True)
'Do something here to add mNewNode to NewDoc
Next
End Function
I just can't work out how to add the cloned node to the new HTML document.
I've tried .appendChild, .insertBefore, and .createElement on various
objects (probably the wrong ones or with incorrect arguments) and the VB
program just locks up.
I am aware that there is only 1 child node of mInputDoc - the <HTML> node -
and therefore the For Next loops just once, but I've specified Deep = True
to copy the whole DOM tree to the new document. There are easier ways to
copy a document, but I want to understand how to do it by copying/cloning
nodes from one document to a new document.
Thanks for any help!
--