473,320 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Referencing objects in mshtml

I'm using the WebBrowser control and mshtml library to modify the HTML in a
web page. E.g. the code below is meant to change all .txt links to .zip,
but doesn't because mAnchorElement is just a copy of mElement and doesn't
reference mElement and any changes I make to it affect the copy and not
mElement.

Private Sub Web1_DocumentComplete(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent ) Handles
Web1.DocumentComplete

Dim mDoc As mshtml.HTMLDocument
Dim mElement As mshtml.IHTMLElement
Dim mAnchorElement As mshtml.IHTMLAnchorElement

mDoc = Web1.Document
For Each mElement In mDoc.body.all
If mElement.tagName = "A" Then
mAnchorElement = mElement
If InStr(mAnchorElement.href, ".txt") Then
Replace(".txt", mAnchorElement.href, ".zip")
End If
End If
Next

End Sub
I could do it using the following code:

Dim mAnchorElements As mshtml.IHTMLElementCollection
mAnchorElements = mDoc.getElementsByTagName("A")
For Each mAnchorElement In mAnchorElements
If InStr(mAnchorElement.href, ".txt") Then
Replace(".txt", mAnchorElement.href, ".zip")
End If
Next

However I change other parts of the HTML (not just certain <A> tags) and was
wondering whether it is possible to loop through mDoc.body.all, 'cast'
mElement to the appropriate object based on the tagName, make changes to
that object and have them reflected in the original mDoc.

So the question is: how do I reference the mElement object in the first code
snippet so that changes to mAnchorElement object affect mElement? I can
then apply the same logic to other ihtml objects.

Thanks for any help.
Nov 21 '05 #1
2 3276
mAnchorElement.href = Replace(".txt", mAnchorElement.href, ".zip")

"J Williams" <Zj********************@Zhotmail.comZ> wrote in message
news:32*************@individual.net...
I'm using the WebBrowser control and mshtml library to modify the HTML in
a web page. E.g. the code below is meant to change all .txt links to
.zip, but doesn't because mAnchorElement is just a copy of mElement and
doesn't reference mElement and any changes I make to it affect the copy
and not mElement.

Private Sub Web1_DocumentComplete(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent ) Handles
Web1.DocumentComplete

Dim mDoc As mshtml.HTMLDocument
Dim mElement As mshtml.IHTMLElement
Dim mAnchorElement As mshtml.IHTMLAnchorElement

mDoc = Web1.Document
For Each mElement In mDoc.body.all
If mElement.tagName = "A" Then
mAnchorElement = mElement
If InStr(mAnchorElement.href, ".txt") Then
Replace(".txt", mAnchorElement.href, ".zip")
End If
End If
Next

End Sub
I could do it using the following code:

Dim mAnchorElements As mshtml.IHTMLElementCollection
mAnchorElements = mDoc.getElementsByTagName("A")
For Each mAnchorElement In mAnchorElements
If InStr(mAnchorElement.href, ".txt") Then
Replace(".txt", mAnchorElement.href, ".zip")
End If
Next

However I change other parts of the HTML (not just certain <A> tags) and
was wondering whether it is possible to loop through mDoc.body.all, 'cast'
mElement to the appropriate object based on the tagName, make changes to
that object and have them reflected in the original mDoc.

So the question is: how do I reference the mElement object in the first
code snippet so that changes to mAnchorElement object affect mElement? I
can then apply the same logic to other ihtml objects.

Thanks for any help.

Nov 21 '05 #2
Thanks, I spotted my mistake. It should actually be:

mAnchorElement.href = Replace(mAnchorElement.href, ".txt", ".zip")

"Jim Hughes" <NO*********@Hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
mAnchorElement.href = Replace(".txt", mAnchorElement.href, ".zip")

"J Williams" <Zj********************@Zhotmail.comZ> wrote in message
news:32*************@individual.net...
I'm using the WebBrowser control and mshtml library to modify the HTML in
a web page. E.g. the code below is meant to change all .txt links to
.zip, but doesn't because mAnchorElement is just a copy of mElement and
doesn't reference mElement and any changes I make to it affect the copy
and not mElement.

Private Sub Web1_DocumentComplete(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent ) Handles
Web1.DocumentComplete

Dim mDoc As mshtml.HTMLDocument
Dim mElement As mshtml.IHTMLElement
Dim mAnchorElement As mshtml.IHTMLAnchorElement

mDoc = Web1.Document
For Each mElement In mDoc.body.all
If mElement.tagName = "A" Then
mAnchorElement = mElement
If InStr(mAnchorElement.href, ".txt") Then
Replace(".txt", mAnchorElement.href, ".zip")
End If
End If
Next

End Sub
I could do it using the following code:

Dim mAnchorElements As mshtml.IHTMLElementCollection
mAnchorElements = mDoc.getElementsByTagName("A")
For Each mAnchorElement In mAnchorElements
If InStr(mAnchorElement.href, ".txt") Then
Replace(".txt", mAnchorElement.href, ".zip")
End If
Next

However I change other parts of the HTML (not just certain <A> tags) and
was wondering whether it is possible to loop through mDoc.body.all,
'cast' mElement to the appropriate object based on the tagName, make
changes to that object and have them reflected in the original mDoc.

So the question is: how do I reference the mElement object in the first
code snippet so that changes to mAnchorElement object affect mElement? I
can then apply the same logic to other ihtml objects.

Thanks for any help.


Nov 21 '05 #3

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

Similar topics

1
by: Dean Hallman | last post by:
I need to ensure client machine has Microsoft.mshtml installed in the GAC. And if not, deploy it. My app is a Browser Helper Object and depends on mshtml. Initially, I thought I could take care...
2
by: Chang | last post by:
Actually I am not sure how to word this question, I will try my best. Remove all the HTML code from a give *.html file and show it as text file. I am using WebBrowser to open (local) html...
10
by: Hans Merkl | last post by:
Hi, I have written an pap with .NET 2.0 and c# that uses MSHTML. It works fine on my development machine but on machines I deploy it to I get the following exception when ever I call MSHTML. ...
2
by: DotNetShadow | last post by:
Hi Guys, I have been reading heaps of information in regards to MSHTML object being used in .NET applications, windows and UI-less. I have read the walkall samples and tried various techniques...
3
by: Pat Mac | last post by:
Ok, I'm stumped. I'm working with the axWebBrowser control and all of the samples talk about adding a reference to the MSHTML library. I have the ..dll in my \windows\system32 directory, but when...
5
by: Atara | last post by:
I am trying to convert the following code to VB .Net, I still have some gaps (the lines that are marked with (*)) and also I need an ending condition for the while loop. any help would be...
0
by: Atara | last post by:
Our application was build with VS 2003. I have tried to run it on a computer with .Net 2.0 (but without .Net 1.1 , as it should be used) and I got the following error - ...
11
by: Lucky | last post by:
hi guys, i need to parse html data that i've got from "Inet" object in vb6. now i want to prase the html data. here i got 2 options. one is MSXML and other is MSHTML. i tried both of them but i...
5
by: Jason | last post by:
Hi, I'm developing an HTML Editor Control using VB.Net 2003 for an application that used to use the DHTML Editor Control that is no longer supported. Well, it's been fun but I've hit a wall with...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.