473,651 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_DocumentCo mplete(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebB rowserEvents2_D ocumentComplete Event) Handles
Web1.DocumentCo mplete

Dim mDoc As mshtml.HTMLDocu ment
Dim mElement As mshtml.IHTMLEle ment
Dim mAnchorElement As mshtml.IHTMLAnc horElement

mDoc = Web1.Document
For Each mElement In mDoc.body.all
If mElement.tagNam e = "A" Then
mAnchorElement = mElement
If InStr(mAnchorEl ement.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.IHTMLEle mentCollection
mAnchorElements = mDoc.getElement sByTagName("A")
For Each mAnchorElement In mAnchorElements
If InStr(mAnchorEl ement.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 3286
mAnchorElement. href = Replace(".txt", mAnchorElement. href, ".zip")

"J Williams" <Zj************ ********@Zhotma il.comZ> wrote in message
news:32******** *****@individua l.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_DocumentCo mplete(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebB rowserEvents2_D ocumentComplete Event) Handles
Web1.DocumentCo mplete

Dim mDoc As mshtml.HTMLDocu ment
Dim mElement As mshtml.IHTMLEle ment
Dim mAnchorElement As mshtml.IHTMLAnc horElement

mDoc = Web1.Document
For Each mElement In mDoc.body.all
If mElement.tagNam e = "A" Then
mAnchorElement = mElement
If InStr(mAnchorEl ement.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.IHTMLEle mentCollection
mAnchorElements = mDoc.getElement sByTagName("A")
For Each mAnchorElement In mAnchorElements
If InStr(mAnchorEl ement.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(mAnchor Element.href, ".txt", ".zip")

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

"J Williams" <Zj************ ********@Zhotma il.comZ> wrote in message
news:32******** *****@individua l.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_DocumentCo mplete(ByVal sender As Object, ByVal e As
AxSHDocVw.DWebB rowserEvents2_D ocumentComplete Event) Handles
Web1.DocumentCo mplete

Dim mDoc As mshtml.HTMLDocu ment
Dim mElement As mshtml.IHTMLEle ment
Dim mAnchorElement As mshtml.IHTMLAnc horElement

mDoc = Web1.Document
For Each mElement In mDoc.body.all
If mElement.tagNam e = "A" Then
mAnchorElement = mElement
If InStr(mAnchorEl ement.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.IHTMLEle mentCollection
mAnchorElements = mDoc.getElement sByTagName("A")
For Each mAnchorElement In mAnchorElements
If InStr(mAnchorEl ement.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
7755
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 of deploying mshtml within my install ..msi (VS.NET setup/deploy project). But if I simply add mshtml to the GAC from my install, the install fails near the end with the error:
2
1774
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 file and using MSHTML to get text from <body> part of html file.
10
10994
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. "Could not load file or assembly 'Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."
2
3756
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 with MSHTML. My biggest problem seems to be running MSHTML in asp.net application and looping elements in the document. Example:
3
5949
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 I'm trying to add the reference to my VB.Net application I keep getting a "namespace or type 'mshtml' for Imports 'mshtml' cannot be found." The code looks like: Imports System Imports Mshtml
5
10899
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 appreciated. Thanks. Atara. ------------------------- Original code:
0
2231
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 - System.InvalidCastException: Unable to cast COM object of type 'mshtml.HTMLBodyClass' to class type ''. COM components that enter the CLR and do not support IProvideClassInfo or that do not have any interop assembly registered will be wrapped in the __ComObject type....
11
2356
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 didnt get anything out of them. MSXML doesnt works with some keywords and consider some letters as operator so i cant go with MSXML. i tried MSHTML but it doesnt provide any way to parse the HTML data you got from other source. there is a...
5
3877
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 an intermittent problem working with editing Hyperlinks. As you can see the following HTML code contains two links each in a paragraph tag. In the Editor, when I highlight the first link and execute code to select,
0
8795
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8695
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6157
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
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
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.