473,320 Members | 1,921 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.

How to Load string into mshtml object?

Can't seem to find anything that works for me. I have a small bit of
HTML that is stored in a string variable. I want to assign this string
to an mshtml object (IHTMLDocument2 I believe), so that I can traverse
the elements and attributes cleanly.
Does anybody know of a way to load this string into an mshtml object?
I would be beholdin'

Tks,
adwooley2

Oct 10 '06 #1
4 6028
Does anybody know of a way to load this string into an mshtml object?

Are you using .NET 2003 or 2005?

--

(O)enone
Oct 10 '06 #2
Using .NET 2005.

Oenone wrote:
Does anybody know of a way to load this string into an mshtml object?

Are you using .NET 2003 or 2005?

--

(O)enone
Oct 10 '06 #3
adwooley2 wrote:
Using .NET 2005.
I've done this using the new VS2005 WebBrowser control. It seemed to be a
little more complex than I was expecting, but still do-able.

Unfortunately the control didn't seem to like being instantiated from
scratch in code, so I had to create a form and place a WebBrowser control on
it. I don't know why this was necessary but it was the only way I could get
it to work. With this done (I've called my form WebBrowserForm, and the
WebBrowser control placed upon it is named WebBrowser), the following code
should do what you want:

\\\
Public Function HtmlDoc(ByVal HTML As String) As Windows.Forms.HtmlDocument

'Create an instance of the form containing the WebBrowser control
dim browserForm as New WebBrowserForm

'Set the document text to be our HTML
browserForm.WebBrowser.DocumentText = HTML

'Wait until the document is loaded
Do Until browserForm.WebBrowser.ReadyState = _
WebBrowserReadyState.Loaded _
Or browserForm.WebBrowser.ReadyState = _
WebBrowserReadyState.Complete
Application.DoEvents()
Loop

'Return the document
Return browserForm.WebBrowser.Document

End Function
///

You can then interrogate the DOM using the returned HtmlDocument object.

HTH,

--

(O)enone
Oct 11 '06 #4
Oenone,
Much appreciated.
Yes, I think that this is what I was looking for. And thanks for the
code - that makes it clearer.

Rgds,
adwooley2
Oenone wrote:
adwooley2 wrote:
Using .NET 2005.

I've done this using the new VS2005 WebBrowser control. It seemed to be a
little more complex than I was expecting, but still do-able.

Unfortunately the control didn't seem to like being instantiated from
scratch in code, so I had to create a form and place a WebBrowser control on
it. I don't know why this was necessary but it was the only way I could get
it to work. With this done (I've called my form WebBrowserForm, and the
WebBrowser control placed upon it is named WebBrowser), the following code
should do what you want:

\\\
Public Function HtmlDoc(ByVal HTML As String) As Windows.Forms.HtmlDocument

'Create an instance of the form containing the WebBrowser control
dim browserForm as New WebBrowserForm

'Set the document text to be our HTML
browserForm.WebBrowser.DocumentText = HTML

'Wait until the document is loaded
Do Until browserForm.WebBrowser.ReadyState = _
WebBrowserReadyState.Loaded _
Or browserForm.WebBrowser.ReadyState = _
WebBrowserReadyState.Complete
Application.DoEvents()
Loop

'Return the document
Return browserForm.WebBrowser.Document

End Function
///

You can then interrogate the DOM using the returned HtmlDocument object.

HTH,

--

(O)enone
Oct 13 '06 #5

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

Similar topics

7
by: Michael Hill | last post by:
If I have: <a href="javascript:myfunct('cool_links')" id="cool_links"> and I refer to it as: function myfunct(mylink) { document.getElementById }
8
by: Jeff Johnson | last post by:
Hi, I've begun converting an ASP site over to .NET and I'm a novice at both the new platform as well as C#. I have a COM+ object that returns a string array when it is called. The size of...
10
by: Wouter vanEck | last post by:
Hi, I need to find a way to read a html type string from a database and add it to a placeholder control on the page and then I need to be able to populate the fields that were in that html...
5
by: Rajesh Kr Shukla | last post by:
Hi There, Can any one suggest me how to convert the string into object in VB.net. If you are familier with javascript you can use. var i = 1 eval("textbox" + i).value = "Hello World" What is...
3
by: Rich | last post by:
Hello, I am converting an app from VB6 to VB.Net and have encountered the following problem. I have the following loop which retrieves objects from a collection of objects. Dim entry As...
4
by: Nikolay Petrov | last post by:
How can I access the MSHTML object in Internet Explorer, from my app? I don't want to use the IE Control and put it in my app. I want to be able to do things with the opened document in the...
3
by: rsine | last post by:
I have searched around a little and have yet to find a naming convention for the string builder object. I really do not want to use "str" since this is for string objects and thus could be...
0
by: John Olbert | last post by:
When I try to load an ActiveX object written in Vb6 that has been added to the Vs2005 tool list I receive this error-- "Failure to create component AxHost, The error message follows:...
6
by: nramrits | last post by:
when i open form in a developer i'm getting err FRM-18108:faild to load a following objects. Source Module : PROG_UNIT.olb Source Object : PROC_RUN_REPORT this error comes perticular forms only ,...
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...
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
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.