472,353 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

HTML DOM cloning nodes to copy document

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!
--

Nov 21 '05 #1
6 8269
John,

When you want to make a copy of the document (be aware that that can be a
frame, a page can have more documents) than you can use in my opinion the
best the outertext from the <HTML> node which include that tag or the
innertext which exclude that tag..

I hope this heps.

Cor
Nov 21 '05 #2
I would like to clone the HTML node directly and add it to a new
HTMLDocument. I can create a new HTMDocument using createElement and
appendChild as shown in the following code:

Dim mHTMLnode, mHEADnode, mTITLEnode, mBODYnode As mshtml.IHTMLDOMNode
Dim NewDoc As mshtml.HTMLDocument

NewDoc = New mshtml.HTMLDocument

mHTMLnode = NewDoc.appendChild(NewDoc.createElement("HTML"))
mHEADnode = mHTMLnode.appendChild(NewDoc.createElement("HEAD") )
mTITLEnode = mHEADnode.appendChild(NewDoc.createElement("TITLE" ))
mTITLEnode.appendChild(NewDoc.createTextNode("The Title"))
mBODYnode = mHTMLnode.appendChild(NewDoc.createElement("BODY") )
As shown in my first post, I can also clone the first node of an existing
document (the HTML node which will contain all the other child nodes) but
can't add it to a new, empty HTMLDocument.

I would expect something like:

mHTMLnode = NewDoc.appendChild(mInputDoc.firstChild)

where mInputDoc is the existing HTMLDocument to work, but it doesn't.

Any ideas?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
John,

When you want to make a copy of the document (be aware that that can be a
frame, a page can have more documents) than you can use in my opinion the
best the outertext from the <HTML> node which include that tag or the
innertext which exclude that tag..

I hope this heps.

Cor

Nov 21 '05 #3
I think you should use importNode
Node importNode(in Node importedNode,
in boolean deep)

this is specified in Document Object Model (DOM) Level 2 Core
SpecificationVersion 1.0W3C Recommendation 13 November, 2000

I dont know if mshtml supports it.

Regards,
alejandro lapeyre

"J Williams" <Zj********************@Zhotmail.comZ> escribió en el mensaje
news:36*************@individual.net...
I would like to clone the HTML node directly and add it to a new
HTMLDocument. I can create a new HTMDocument using createElement and
appendChild as shown in the following code:

Dim mHTMLnode, mHEADnode, mTITLEnode, mBODYnode As mshtml.IHTMLDOMNode
Dim NewDoc As mshtml.HTMLDocument

NewDoc = New mshtml.HTMLDocument

mHTMLnode = NewDoc.appendChild(NewDoc.createElement("HTML"))
mHEADnode = mHTMLnode.appendChild(NewDoc.createElement("HEAD") )
mTITLEnode = mHEADnode.appendChild(NewDoc.createElement("TITLE" ))
mTITLEnode.appendChild(NewDoc.createTextNode("The Title"))
mBODYnode = mHTMLnode.appendChild(NewDoc.createElement("BODY") )
As shown in my first post, I can also clone the first node of an existing
document (the HTML node which will contain all the other child nodes) but
can't add it to a new, empty HTMLDocument.

I would expect something like:

mHTMLnode = NewDoc.appendChild(mInputDoc.firstChild)

where mInputDoc is the existing HTMLDocument to work, but it doesn't.

Any ideas?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
John,

When you want to make a copy of the document (be aware that that can be a
frame, a page can have more documents) than you can use in my opinion the
best the outertext from the <HTML> node which include that tag or the
innertext which exclude that tag..

I hope this heps.

Cor


Nov 21 '05 #4
John,

You need (direct or by late binding) to use MSHTML for that. It is not an
easy job to use that and even more a problem to help somebody with this in a
newsgroup. Do not use an import to that however refence it everytime again.
It freezes your IDE because of the endless interfaces.

mshtml
http://msdn.microsoft.com/library/de...ng/hosting.asp
I hope this helps a little bit?

I hope this helps something.

Cor
Nov 21 '05 #5
Hi, Thanks for your reply.

Isn't importNode the equivalent of cloneNode for XML documents? They have
the same arguments. I'm already using cloneNode to clone the <HTML> </HTML>
node, but there seems to be no way of adding the node to an empty
HTMLDocument.

"alejandro lapeyre" <al**************@jotmail.com> wrote in message
news:O6**************@TK2MSFTNGP14.phx.gbl...
I think you should use importNode
Node importNode(in Node importedNode,
in boolean deep)

this is specified in Document Object Model (DOM) Level 2 Core
SpecificationVersion 1.0W3C Recommendation 13 November, 2000

I dont know if mshtml supports it.

Regards,
alejandro lapeyre

"J Williams" <Zj********************@Zhotmail.comZ> escribió en el mensaje
news:36*************@individual.net...
I would like to clone the HTML node directly and add it to a new
HTMLDocument. I can create a new HTMDocument using createElement and
appendChild as shown in the following code:

Dim mHTMLnode, mHEADnode, mTITLEnode, mBODYnode As mshtml.IHTMLDOMNode
Dim NewDoc As mshtml.HTMLDocument

NewDoc = New mshtml.HTMLDocument

mHTMLnode = NewDoc.appendChild(NewDoc.createElement("HTML"))
mHEADnode = mHTMLnode.appendChild(NewDoc.createElement("HEAD") )
mTITLEnode = mHEADnode.appendChild(NewDoc.createElement("TITLE" ))
mTITLEnode.appendChild(NewDoc.createTextNode("The Title"))
mBODYnode = mHTMLnode.appendChild(NewDoc.createElement("BODY") )
As shown in my first post, I can also clone the first node of an existing
document (the HTML node which will contain all the other child nodes) but
can't add it to a new, empty HTMLDocument.

I would expect something like:

mHTMLnode = NewDoc.appendChild(mInputDoc.firstChild)

where mInputDoc is the existing HTMLDocument to work, but it doesn't.

Any ideas?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
John,

When you want to make a copy of the document (be aware that that can be
a frame, a page can have more documents) than you can use in my opinion
the best the outertext from the <HTML> node which include that tag or
the innertext which exclude that tag..

I hope this heps.

Cor



Nov 21 '05 #6
There should be some differences.
Every node belongs to a document (the one used to create the node).
I think you can only insert to a document nodes created with that document.
Thats why importNode was defined.

"J Williams" <Zj********************@Zhotmail.comZ> escribió en el mensaje
news:36*************@individual.net...
Hi, Thanks for your reply.

Isn't importNode the equivalent of cloneNode for XML documents? They have
the same arguments. I'm already using cloneNode to clone the <HTML>
</HTML> node, but there seems to be no way of adding the node to an empty
HTMLDocument.

"alejandro lapeyre" <al**************@jotmail.com> wrote in message
news:O6**************@TK2MSFTNGP14.phx.gbl...
I think you should use importNode
Node importNode(in Node importedNode,
in boolean deep)

this is specified in Document Object Model (DOM) Level 2 Core
SpecificationVersion 1.0W3C Recommendation 13 November, 2000

I dont know if mshtml supports it.

Regards,
alejandro lapeyre

"J Williams" <Zj********************@Zhotmail.comZ> escribió en el
mensaje news:36*************@individual.net...
I would like to clone the HTML node directly and add it to a new
HTMLDocument. I can create a new HTMDocument using createElement and
appendChild as shown in the following code:

Dim mHTMLnode, mHEADnode, mTITLEnode, mBODYnode As mshtml.IHTMLDOMNode
Dim NewDoc As mshtml.HTMLDocument

NewDoc = New mshtml.HTMLDocument

mHTMLnode = NewDoc.appendChild(NewDoc.createElement("HTML"))
mHEADnode = mHTMLnode.appendChild(NewDoc.createElement("HEAD") )
mTITLEnode = mHEADnode.appendChild(NewDoc.createElement("TITLE" ))
mTITLEnode.appendChild(NewDoc.createTextNode("The Title"))
mBODYnode = mHTMLnode.appendChild(NewDoc.createElement("BODY") )
As shown in my first post, I can also clone the first node of an
existing document (the HTML node which will contain all the other child
nodes) but can't add it to a new, empty HTMLDocument.

I would expect something like:

mHTMLnode = NewDoc.appendChild(mInputDoc.firstChild)

where mInputDoc is the existing HTMLDocument to work, but it doesn't.

Any ideas?
"Cor Ligthert" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
John,

When you want to make a copy of the document (be aware that that can be
a frame, a page can have more documents) than you can use in my opinion
the best the outertext from the <HTML> node which include that tag or
the innertext which exclude that tag..

I hope this heps.

Cor



Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon | last post by:
Hi, I have generated an xml document, and would like to be able to transform it to another such that the contents of a chosen node type are...
1
by: Philipp Schumann | last post by:
Hi, I have the following code to copy nodes from an XML document (XmlReader reader) to some output (XmlWriter writer). while (reader.Read ())...
0
by: meh | last post by:
Greetings all; Got some questions about cloning a treenode.... In this example: private void button4_Click(object sender, System.EventArgs...
8
by: kurotsuke | last post by:
Hi, I need to clone a class (called NodeAbstract) that I derived from TreeNode. I need to clone it to support drag and drop on the treeview. I...
8
by: Tom | last post by:
I've a problem. I want to clone an object having a list of other objects (and so on :/). Do you know any other way than ICloneable.Clone()...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last...
3
by: raylopez99 | last post by:
The "C# Cookbook" (O'Reilly / Jay Hilyard), section 3.26, is on deep cloning versus shallow cloning. The scanned pages of this book are found...
9
gits
by: gits | last post by:
This short article introduces a method that may be used to create a 'deep-copy' of an javascript object. You might ask: 'Wherefore do we need this?'...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.