473,583 Members | 3,556 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_D ocumentComplete event using:

Dim mNewDoc As mshtml.IHTMLDoc ument3
mNewDoc = NewDoc(axWebBro wser1.Document)
Private Function NewDoc(ByVal mInputDoc As mshtml.IHTMLDoc ument3) As
mshtml.IHTMLDoc ument3
Dim mNodes As mshtml.IHTMLDOM ChildrenCollect ion
Dim mNode, mNewNode As mshtml.IHTMLDOM Node
Dim i As Integer

NewDoc = New mshtml.HTMLDocu ment

mNodes = mInputDoc.child Nodes
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 8385
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.IHTMLDOM Node
Dim NewDoc As mshtml.HTMLDocu ment

NewDoc = New mshtml.HTMLDocu ment

mHTMLnode = NewDoc.appendCh ild(NewDoc.crea teElement("HTML "))
mHEADnode = mHTMLnode.appen dChild(NewDoc.c reateElement("H EAD"))
mTITLEnode = mHEADnode.appen dChild(NewDoc.c reateElement("T ITLE"))
mTITLEnode.appe ndChild(NewDoc. createTextNode( "The Title"))
mBODYnode = mHTMLnode.appen dChild(NewDoc.c reateElement("B ODY"))
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.appendCh ild(mInputDoc.f irstChild)

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

Any ideas?
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.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
SpecificationVe rsion 1.0W3C Recommendation 13 November, 2000

I dont know if mshtml supports it.

Regards,
alejandro lapeyre

"J Williams" <Zj************ ********@Zhotma il.comZ> escribió en el mensaje
news:36******** *****@individua l.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.IHTMLDOM Node
Dim NewDoc As mshtml.HTMLDocu ment

NewDoc = New mshtml.HTMLDocu ment

mHTMLnode = NewDoc.appendCh ild(NewDoc.crea teElement("HTML "))
mHEADnode = mHTMLnode.appen dChild(NewDoc.c reateElement("H EAD"))
mTITLEnode = mHEADnode.appen dChild(NewDoc.c reateElement("T ITLE"))
mTITLEnode.appe ndChild(NewDoc. createTextNode( "The Title"))
mBODYnode = mHTMLnode.appen dChild(NewDoc.c reateElement("B ODY"))
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.appendCh ild(mInputDoc.f irstChild)

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

Any ideas?
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.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******** ******@TK2MSFTN GP14.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
SpecificationVe rsion 1.0W3C Recommendation 13 November, 2000

I dont know if mshtml supports it.

Regards,
alejandro lapeyre

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

Dim mHTMLnode, mHEADnode, mTITLEnode, mBODYnode As mshtml.IHTMLDOM Node
Dim NewDoc As mshtml.HTMLDocu ment

NewDoc = New mshtml.HTMLDocu ment

mHTMLnode = NewDoc.appendCh ild(NewDoc.crea teElement("HTML "))
mHEADnode = mHTMLnode.appen dChild(NewDoc.c reateElement("H EAD"))
mTITLEnode = mHEADnode.appen dChild(NewDoc.c reateElement("T ITLE"))
mTITLEnode.appe ndChild(NewDoc. createTextNode( "The Title"))
mBODYnode = mHTMLnode.appen dChild(NewDoc.c reateElement("B ODY"))
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.appendCh ild(mInputDoc.f irstChild)

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

Any ideas?
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.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************ ********@Zhotma il.comZ> escribió en el mensaje
news:36******** *****@individua l.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******** ******@TK2MSFTN GP14.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
SpecificationVe rsion 1.0W3C Recommendation 13 November, 2000

I dont know if mshtml supports it.

Regards,
alejandro lapeyre

"J Williams" <Zj************ ********@Zhotma il.comZ> escribió en el
mensaje news:36******** *****@individua l.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
appendChil d as shown in the following code:

Dim mHTMLnode, mHEADnode, mTITLEnode, mBODYnode As mshtml.IHTMLDOM Node
Dim NewDoc As mshtml.HTMLDocu ment

NewDoc = New mshtml.HTMLDocu ment

mHTMLnode = NewDoc.appendCh ild(NewDoc.crea teElement("HTML "))
mHEADnode = mHTMLnode.appen dChild(NewDoc.c reateElement("H EAD"))
mTITLEnode = mHEADnode.appen dChild(NewDoc.c reateElement("T ITLE"))
mTITLEnode.appe ndChild(NewDoc. createTextNode( "The Title"))
mBODYnode = mHTMLnode.appen dChild(NewDoc.c reateElement("B ODY"))
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.appendCh ild(mInputDoc.f irstChild)

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

Any ideas?
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:%2******** ********@TK2MSF TNGP10.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
4202
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 flattened (i.e. tags removed). e.g. <shop> <name>super</name> <sells> <drink>squash</drink>
1
1792
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 ()) if (reader.MoveToContent () == XmlNodeType.Element) break; // forward the reader to the document element writer.WriteStartDocument (false);
0
1066
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 e) { TreeNode lastNode = treeView1.Nodes. Nodes.Nodes.Count - 1];
8
5428
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 tried to use the MemberWiseClone (in my own Clone() method) method but with no success. The cloned object seems to be correctly created but I cannot add it to the treeview (I get no error message...
8
4861
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() implementation for all classes in the way? Help..
2
3047
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 reference to the block and thus destory the block is what I'm hoping to achieve. I've never before had to use Javascript closures, but now I do, so I'm making an effort to understand them. I've been...
3
8744
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 here: http://www.sendspace.com/file/mjyocg (Word format, 3 pp) My question, coming from a C++ background where deep copying is done, is why in C# you would do either deep or shallow copying as...
9
13290
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?' ... Answer: 'Only variable-values of the basic data-types string, int, float, boolean and to make the confusion perfect :) functions too! are passed by value, all others are passed by reference.' This...
0
7894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8320
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5697
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5370
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3814
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3841
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1424
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1152
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.