|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 > Does anybody know of a way to load this string into an mshtml object? Are you using .NET 2003 or 2005?-- (O)enone Using .NET 2005.
Oenone wrote: Show quoteHide quote > > Does anybody know of a way to load this string into an mshtml object? > > Are you using .NET 2003 or 2005? > > -- > > (O)enone 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 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: Show quoteHide quote > 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
class library
Locating Windows Application Installation Keys Something I don't quite understand about "file in use by another process" exceptions..... Detect WiFi Networks Adding rows to a data table: Rows do not show up what method to use to add 1 day to a date (hotel reservation for one night by clicking on calender) PLEASE HELP - Executable properties - right click Variable precision Saving color changes for next login How to send output ticket Printer(VB005) |
|||||||||||||||||||||||