Writing an HTML string to an mshtml.Document

D

Desmond Cassidy

Hi,
I have being trying to get a grip of HTML data manipulation and am using the mshtml class and System.Net to retriver HTML pages.

Now as far as I can see, one can read HTML in different ways.

1. Using the WebBrowser and loading the HTML into the mshtml.HTMLDocument class and then step through the various tags (input, a), tables etc.
2. Use System.Net.WebRequest/Response to load the data into a HTML string using a Stream Reader.

Now there are times when I want to use the WebBrowser as it is handy for user input (and maybe show the user what is going on) and other times a more convenient method is to use the System.Net.WebRequest/Response metods.

However, I cannot for the life of me see how one can LOAD up an mshtml.HTMLDocument object with a plain HTML string that I may have got from using the System.Net.WebRequest/Response ....and vice versa...

Any clues ??

Cheers
 
C

Charles Law

Hi Desmond

The document object exposes the IPersistStreamInit interface. The sequence
would be this:

Navigate to about:blank
Wait for readyState to indicate "complete"
Get IPersistStreamInit interface from document
Call InitNew
Call Load
Wait for readyState to indicate "complete"

HTH

Charles


Hi,
I have being trying to get a grip of HTML data manipulation and am using
the mshtml class and System.Net to retriver HTML pages.

Now as far as I can see, one can read HTML in different ways.

1. Using the WebBrowser and loading the HTML into the
mshtml.HTMLDocument class and then step through the various tags (input, a),
tables etc.
2. Use System.Net.WebRequest/Response to load the data into a HTML
string using a Stream Reader.

Now there are times when I want to use the WebBrowser as it is handy for
user input (and maybe show the user what is going on) and other times a more
convenient method is to use the System.Net.WebRequest/Response metods.

However, I cannot for the life of me see how one can LOAD up an
mshtml.HTMLDocument object with a plain HTML string that I may have got
from using the System.Net.WebRequest/Response ....and vice versa...

Any clues ??

Cheers
 
D

Desmond Cassidy

Mant thanks Charles,.....

I'll have a look later today and report back...I have seen this
'IPersistStreamInit' interface is some example code but never understood
what it was for...

Till later...

Cheers,

Desmond.
 
D

Desmond Cassidy

Hi Charles,
OK...I am missing something !!!

How do I reference IPersistStreamInit in VB.Net ?

I have trawled the Internet and MSDN to no avail....

I have tried Adding References, Imports system.x.y.z etc....and I still
cannot get that simple line

Dim ips as IPersistStreamInit to compile ???

Confused...

Cheers,

Desmond.
 
C

Charles Law

Hi Desmond

Sorry, here is one I made earlier

<code>
Public Enum HRESULT
S_OK = 0
S_FALSE = 1
E_NOTIMPL = &H80004001
E_INVALIDARG = &H80070057
E_NOINTERFACE = &H80004002
E_FAIL = &H80004005
E_UNEXPECTED = &H8000FFFF
End Enum

' IPersistStreamInit interface
<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersistStreamInit : Inherits IPersist

' IPersist interface
Shadows Sub GetClassID(ByRef pClassID As Guid)

<PreserveSig()> Function IsDirty() As Integer
<PreserveSig()> Function Load(ByVal pstm As UCOMIStream) As HRESULT
<PreserveSig()> Function Save(ByVal pstm As UCOMIStream,
<MarshalAs(UnmanagedType.Bool)> ByVal fClearDirty As Boolean) As HRESULT
<PreserveSig()> Function GetSizeMax(<InAttribute(), Out(),
MarshalAs(UnmanagedType.U8)> ByRef pcbSize As Long) As HRESULT
<PreserveSig()> Function InitNew() As HRESULT

End Interface
</code>

HTH

Charles
 
D

Desmond Cassidy

Hi Charles...
I am still none the wiser....what do I have to reference or to make it
simple...it still comes up with

D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(95):
Attribute cannot be used on 'IPersistStreamInit'.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(95): 'Guid'
cannot be used as an attribute because it is not a class.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(95): Type
'ComImport' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(95): Type
'ComVisible' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(105): Type
'InAttribute' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(96): Type
'InterfaceTypeAttribute' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(97): Type
'IPersist' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(105): Type
'MarshalAs' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(104): Type
'MarshalAs' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(105): Type
'Out' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(106): Type
'PreserveSig' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(103): Type
'PreserveSig' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(104): Type
'PreserveSig' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(102): Type
'PreserveSig' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(105): Type
'PreserveSig' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(103): Type
'UCOMIStream' is not defined.
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(104): Type
'UCOMIStream' is not defined.

Show I so some import ???


Imports System.???????????

Sorry...I still haven't a clue why I have to put all this NON .Net code
in here ???

Cheers,

Dersmond.
 
C

Charles Law

Hi Desmond

The import you need is

Imports System.Runtime.InteropServices

Include the stuff I posted last time in a separate class file (for
neatness), and include it in your project with the import above.

..NET does not define the IPersistStreamInit interface, which is why you need
to define it yourself. If you were doing this in C++ you would just include
a header file containing the definition, but VB.NET doesn't have an
equivalent predefined version.

Charles
 
D

Desmond Cassidy

Hi Charles,
Many thanks for your patience....
Yes...this COM stuff is still a little bewildering to me...I came into VB at the .NET stage and haven't had much exposure to these concepts.
So effectively what is happening is we are creating the glue (interface) for the DOM (Document Object Model) ?

OK, I have included Imports System.Runtime.InteropServices and everything is OK apart from the line

<ComVisible(True), ComImport(), Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"), InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> Public Interface IPersistStreamInit : Inherits IPersist


The : Inherits IPersist (at the end of the line) is still showing up as
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(98): Type 'IPersist' is not defined.

So this itself I imagine should just be an Interface such as
Public Interface IPersist

End Interface

However I am sure there should be some code in this ??? or is it referenced elsewhere ???



===============================================

Again many thanks for your own 'Persistance' with me ;-)



Cheers,



Desmond.
 
C

Charles Law

Desmond

Many apologies. I had not intended to leave that bit out. I didn't spot it
on the end of the line.

Here it is

<code>
' IPersist interface
<ComVisible(True), ComImport(),
Guid("0000010c-0000-0000-C000-000000000046"), _
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> _
Public Interface IPersist
Sub GetClassID(ByRef pClassID As Guid)
End Interface
</code>

I could have done it another way, w/o needing the extra interface, but doing
it this way gives a more literal translation of the original.

I hope that covers it, but please don't worry about posting back if I have
missed anything else.

Charles


Hi Charles,
Many thanks for your patience....
Yes...this COM stuff is still a little bewildering to me...I came into
VB at the .NET stage and haven't had much exposure to these concepts.
So effectively what is happening is we are creating the glue (interface)
for the DOM (Document Object Model) ?

OK, I have included Imports System.Runtime.InteropServices and
everything is OK apart from the line

<ComVisible(True), ComImport(),
Guid("7FD52380-4E07-101B-AE2D-08002B2EC713"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)> Public
Interface IPersistStreamInit : Inherits IPersist
The : Inherits IPersist (at the end of the line) is still showing up as
D:\Visual Studio Private Projects\ScreenScrape\WebUtilities.vb(98): Type
'IPersist' is not defined.

So this itself I imagine should just be an Interface such as
Public Interface IPersist
End Interface
However I am sure there should be some code in this ??? or is it referenced
elsewhere ???

===============================================
Again many thanks for your own 'Persistance' with me ;-)

Cheers,

Desmond.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top