Well that wasn't as simple as it may sound. The reason is discussed in
the posting [1] from Praveen Kosuri @ Microsoft. An extract...

"What you have found is the way to write to the HTMLDOcument from a .NET
application. If you use VB6 to do this,internally, VB6 virtual machine
automatically initializes MSHTML.HTMLDocument (with
"<html><body></body></html>"). After initializing, the Length of the
object
works correctly. However, in .NET world (VB.NET or C# for that matter),
you
need to explicitly initialize the object before calling any methods. And
how to do that? It is done using methods of IPersistStreamInit interface
(like you did ). COM Interop Services provides wrappers for any
interfaces
(checkout members of System.Runtime.InteropServices). However, it does
not
provide a wrapper for this interface. You will need to implement the
interface yourself."

The *only* way I could get this to work (and there may be others) is as
follows:

IHTMLDocument2 doc = new HTMLDocumentClass();
doc.write("<html>nothing to see here!</html>"); //this can be any HTML
doc.close();    //close and the doc is set to readyState "complete" (if
you don't it stays at "loading")

while (doc.readyState != "complete")
        System.Threading.Thread.Sleep(50);

MessageBox.Show(doc.body.InnerHTML);    //<BODY>nothing to see
here!</BODY>

//Continue....

I'm still working through what I want to do, but I verified that this
works :)

There is an issue however at [2] that says you sholdn't really do this
with scripting, although I get the impression that it for handling
events; rather than the simple getElementsByTagName() stuff I wanna do!
(i.e. I'm going to use it...).

Cheers,
Steven.

[1] "Headless mshtml"
http://www.dotnet247.com/247reference/msgs/20/100435.aspx

[2] "Hosting MSHTML With Scripting Activated Causes Instability"
http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q266343&;


-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED]] On Behalf Of Kirk Allen
Evans
Sent: Friday, July 26, 2002 10:12 AM
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] DHTML Document Model in C#


> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED]]On Behalf Of Erick
> Thompson
> Sent: Thursday, July 25, 2002 5:32 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] DHTML Document Model in C#
>
> work. If you go this route, I would like to know if you have any
> success in using mshtml without creating a WinForm.


I didn't see the post regarding mshtml without a winform, but you should
be
able to simply use it as a parser through interop.  This is VB6 code,
but it
should work the same in .NET and should not require a UI.  Is this
similar
to what you already tried?  If so, what issues did you have?

   Dim doc As MSHTML.HTMLDocument
   Dim node As MSHTML.IHTMLElement

   Set doc = New MSHTML.HTMLDocument
   doc.body.innerHTML =
"<html><head><title>test</title></head><body><h1>Hello,world</h1><span
id=""test"">A test</span></body></html>"

   Set node = doc.getElementById("test")
   Debug.Print node.innerText

   Set node = Nothing
   Set doc = Nothing

Kirk Allen Evans
http://www.xmlandasp.net
"XML and ASP.NET", New Riders Publishing
http://www.amazon.com/exec/obidos/ASIN/073571200X

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to