How can you implement MSHTML.HTMLDocument in ASP???

J

Jay Kappel

I sure hope someone can help. I have been searching the net non stop for a
week now and there are ZERO references to how this can be accomplished. I
am using ASP (not .Net) on an IIS 6.0 server and I have control of that
server. I would like to be able to implement the Microsoft HTML Object
Library into my asp script. The following works in vb6...

Dim m As MSHTML.HTMLDocument, d As Object

Set m = New MSHTML.HTMLDocument
Set d = m.createDocumentFromUrl("http://www.quicken.com", vbNullString)
Do
DoEvents
Loop While d.readyState <> "complete"

Text1.Text = d.documentElement.outerHTML

However, when you dim m as an object (which is what you do in IIS) it is no
longer able to find the CreateDocumentFromUrl method. Can someone please
help??

Thanks, Jay Kappel

PS - The IIS version that does not work but should is...

Dim m, d

Set m = New MSHTML.HTMLDocument
Set d = m.createDocumentFromUrl("http://www.quicken.com", vbNullString)
Do
'DoEvents
Loop While d.readyState <> "complete"

Response.Write d.documentElement.outerHTML

Also, is there something special I need to do so that the MSHTML library is
available to ASP scripts? I figure there may be an IIS modification I need
to do.
 
F

F@yy@Z

Never used MSHTML.HTMLDocument

But you can try this code in ASP I think this will help..
<%
Set objXML = server.CreateObject("Microsoft.XMLHTTP")
objXML.Open "Get", "http://www.quicken.com", False
objXML.send
strbody = objXML.responseText

Set objXML = nothing
Response.Write strbody
%>
 
J

Jay Kappel

Thanks for the answer, but that's not what I am looking for. The Microsoft
XMLHTTP object returns the HTML data as a string. The method I am using
loads the html into a Html DOM object that can be navigated like the client
DOM. So what I really need is access to the DOM in ASP.

Again any help Greatly Appreciated!
 
B

Bob Barrows [MVP]

Jay said:
I sure hope someone can help. I have been searching the net non stop
for a week now and there are ZERO references to how this can be
accomplished. I am using ASP (not .Net) on an IIS 6.0 server and I
have control of that server. I would like to be able to implement
the Microsoft HTML Object Library into my asp script. The following
works in vb6...

Dim m As MSHTML.HTMLDocument, d As Object

Set m = New MSHTML.HTMLDocument
Set d = m.createDocumentFromUrl("http://www.quicken.com",
vbNullString) Do
DoEvents
Loop While d.readyState <> "complete"

Text1.Text = d.documentElement.outerHTML

However, when you dim m as an object (which is what you do in IIS) it
is no longer able to find the CreateDocumentFromUrl method. Can
someone please help??

Thanks, Jay Kappel

According to this, it seems it is not possible:
http://groups.google.com/groups?hl=...en&lr=&ie=UTF-8&oe=UTF-8&c2coff=1&sa=N&tab=wg

Bob Barrows
 
J

Jay Kappel

I have been wrestling with the idea that it's not possable as well, but then
I found a few hosting companies that says by default they have support for
the Microsoft HTML Object Library in their asp hosting package. So it has
to be possable. I just can't find a sample of how to do it anywhere!

Here are the hosting companies:

http://www.3shost.com/commandmatrix.html
http://www.spaceforhosting.com/pages/reseller/windows/index.php
http://www.hostonnet.com/windows_reseller.php
etc..

Still searching...
 
J

Jay Kappel

Thanks again... This control however does not provide a DOM object, just a
means of getting the http code.

Jay Kappel
 
J

Jay Kappel

OK, how about this. Can anyone tell me at least how to use the
CreateObject(class,[servername]) statement with the mshtml.dll?

So if class is made up of the appname.object type then
CreateObject("mshtml.HTMLDocument") should do it according th VBs object
browser. The problem is that I get: Microsoft VBScript runtime error
'800a01ad' as a result. Here is what Microsoft has to say about it:

This error is usually generated because dynamic-link libraries (DLLs) on
which the COM object depends are one of the following:
a.. Missing from the system
b.. Not in the system path
c.. Not accessible by the system because of security settings

Well, It's not missing, it's in the system32 path, but I have no idea what
security settings to look at. Can anyone help??

Thanks, Jay Kappel
 
Y

Yan-Hong Huang[MSFT]

Hello Jay,

Where is the scripting running on? Client side or server side? If server
side, you can't do that since the DOM is a client-side thing, within the
browser. It doesn't exist on the server, and you can't access it from the
server to the client.

Have you though of the following methods?

1) Use XMLHttp object to get the content of the string and then parse it by
using the method at
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downlo
ads/samples/internet/browser/walkall/default.asp.

The above WALKALL sample demonstrates the use of MSHTML as a UI-less HTML
parser.

2) As
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&c2coff=1&threadm
=mKdBZma%24CHA.2252%40cpmsftngxa08.phx.gbl&rnum=30&prev=/groups%3Fq%3DMSHTML
.HTMLDocument%2Basp%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26c2coff%3D1
%26start%3D20%26sa%3DN mentioned, use a AxWebBrowser to act as the client
side. We'll have the AxWebBrowser.Navigate() to retrieve some URLs back. So
we can get DOM object in OnDocumentComplete method.

Hope that helps.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Chris Hohmann

Jay Kappel said:
OK, how about this. Can anyone tell me at least how to use the
CreateObject(class,[servername]) statement with the mshtml.dll?

So if class is made up of the appname.object type then
CreateObject("mshtml.HTMLDocument") should do it according th VBs object
browser. The problem is that I get: Microsoft VBScript runtime error
'800a01ad' as a result. Here is what Microsoft has to say about it:

This error is usually generated because dynamic-link libraries (DLLs) on
which the COM object depends are one of the following:
a.. Missing from the system
b.. Not in the system path
c.. Not accessible by the system because of security settings

Well, It's not missing, it's in the system32 path, but I have no idea what
security settings to look at. Can anyone help??

I did some investigating and the consensus seems to be that to access
mshtml.dll from ASP (Classic), you need to create a COM wrapper. A recurring
theme in the google threads I reads seems to be the difficulty people
encountered with the asynchonous nature of retreiving remote content via
mshtml.dll. As such here's how I might approach it. Create a Windows
Scripting Component (WSC) that does the following:

1. Instantiate an MSHTML.HTMLDocument object
2. Instantiate an MSXML.ServerXMLHTTP object
3. Retreive the remote content using the ServerXMLHTTP object and pass it as
a stream using the responseStream property to the IPeristStreamInit
interface that the HTMLDocument implements.
4. "Walk" the DOM represented by the HTMLDocument and perform any
manipulation necessary
5. You can then stream the modified content directly to the ASP.Response
object since it also implements the IStream interface. Or you could simply
return a string, or save it to a file, etc...

Notes:
1. I realize the above is simply a bunch of hand waving. Time permitting, I
will try to followup with a proof of concept, unless of course you beat me
to it. :)
2. Windows Scripting Components feels like a good fit here. They are
honest-to-goodness COM objects that don't need to be registed, or more
precisely, can be registered dynamically.
3. By using the ServerXMLHTTP instead of HTMLDocument to retreive the remote
content, you bypass all the ugliness of instantiating wininet.dll. This is
nice since all you really wanted was the parsing ability of mshtml.dll.

Interested to see what you come up with.
-Chris Hohmann
 
J

J. Baute

Jay Kappel said:
I sure hope someone can help. I have been searching the net non stop for a
week now and there are ZERO references to how this can be accomplished. I
am using ASP (not .Net) on an IIS 6.0 server and I have control of that
server. I would like to be able to implement the Microsoft HTML Object
Library into my asp script. The following works in vb6...

Dim m As MSHTML.HTMLDocument, d As Object

Set m = New MSHTML.HTMLDocument
Set d = m.createDocumentFromUrl("http://www.quicken.com", vbNullString)
Do
DoEvents
Loop While d.readyState <> "complete"

Text1.Text = d.documentElement.outerHTML

However, when you dim m as an object (which is what you do in IIS) it is no
longer able to find the CreateDocumentFromUrl method. Can someone please
help??

Thanks, Jay Kappel

PS - The IIS version that does not work but should is...

Dim m, d

Set m = New MSHTML.HTMLDocument
Set d = m.createDocumentFromUrl("http://www.quicken.com", vbNullString)
Do
'DoEvents
Loop While d.readyState <> "complete"

Response.Write d.documentElement.outerHTML

Also, is there something special I need to do so that the MSHTML library is
available to ASP scripts? I figure there may be an IIS modification I need
to do.

I wanted to do a simular thing myself once, and didn't find any way of
achieving this either using serverside ASP.

I ended up shifting the whole thing clientside, where I let the whole
DOM manipulation being handled by clientside JavaScript, which was
fine what I wanted to do.

One other possible way I can think of to be able to do something
serverside, is by converting the HTML documents to XHTML, which will
make it possible to access them using the XML DOM objects.
 
J

Jay Kappel

Chris,

Thanks You!!! Finally someone who understands what I am asking.
The approach you came up with sounds really great to me, and I will get
working on it today. The only problem is that I do not know how to create a
windows scripting component. I am sure google will have something to say
about that.

Also, If you are able to do a "proof of concept" I would be really
appreciative of that as well. Thanks so much..

Jay Kappel

Chris Hohmann said:
Jay Kappel said:
OK, how about this. Can anyone tell me at least how to use the
CreateObject(class,[servername]) statement with the mshtml.dll?

So if class is made up of the appname.object type then
CreateObject("mshtml.HTMLDocument") should do it according th VBs object
browser. The problem is that I get: Microsoft VBScript runtime error
'800a01ad' as a result. Here is what Microsoft has to say about it:

This error is usually generated because dynamic-link libraries (DLLs) on
which the COM object depends are one of the following:
a.. Missing from the system
b.. Not in the system path
c.. Not accessible by the system because of security settings

Well, It's not missing, it's in the system32 path, but I have no idea what
security settings to look at. Can anyone help??

I did some investigating and the consensus seems to be that to access
mshtml.dll from ASP (Classic), you need to create a COM wrapper. A recurring
theme in the google threads I reads seems to be the difficulty people
encountered with the asynchonous nature of retreiving remote content via
mshtml.dll. As such here's how I might approach it. Create a Windows
Scripting Component (WSC) that does the following:

1. Instantiate an MSHTML.HTMLDocument object
2. Instantiate an MSXML.ServerXMLHTTP object
3. Retreive the remote content using the ServerXMLHTTP object and pass it as
a stream using the responseStream property to the IPeristStreamInit
interface that the HTMLDocument implements.
4. "Walk" the DOM represented by the HTMLDocument and perform any
manipulation necessary
5. You can then stream the modified content directly to the ASP.Response
object since it also implements the IStream interface. Or you could simply
return a string, or save it to a file, etc...

Notes:
1. I realize the above is simply a bunch of hand waving. Time permitting, I
will try to followup with a proof of concept, unless of course you beat me
to it. :)
2. Windows Scripting Components feels like a good fit here. They are
honest-to-goodness COM objects that don't need to be registed, or more
precisely, can be registered dynamically.
3. By using the ServerXMLHTTP instead of HTMLDocument to retreive the remote
content, you bypass all the ugliness of instantiating wininet.dll. This is
nice since all you really wanted was the parsing ability of mshtml.dll.

Interested to see what you come up with.
-Chris Hohmann
 
C

Chris Hohmann

Jay Kappel said:
Chris,

Thanks You!!! Finally someone who understands what I am asking.
The approach you came up with sounds really great to me, and I will get
working on it today. The only problem is that I do not know how to create a
windows scripting component. I am sure google will have something to say
about that.

Yeah, it's both a blessing and a curse that WSC doesn't get much attention.
A blessing because most hosting services are unawares that this technology
allows developers to dynamically register their own custom components, but a
curse because there are few examples that showcase the potential of WSC. One
shining exception are the WSC articles at the http://4guysfromrolla.com
site. Just do a search on "WSC". Also, here's a link to the documentation at
the MSDN Library:

http://msdn.microsoft.com/library/en-us/script56/html/lettitle.asp

If you control the box that IIS is running on and the component will not be
changing frequently there's no reason you could create the component is
VB/C++ if you're more comfortable in those environments. You would also see
a performance gain as componenets in those languages would be precompiled.
Also, if you have the .NET framework installed, it becomes a moot point as
you could reference mshtml directly from an ASP.NET app.

Also, If you are able to do a "proof of concept" I would be really
appreciative of that as well. Thanks so much..

It's been a tough weekend. Pulled an all-nighter last night and will need to
crash pretty soon. First work then "play". It's unlikely I would be able to
devote any time to this until the weekend.

-Chris Hohmann
 
C

Chris Hohmann

If you control the box that IIS is running on and the component will not be
changing frequently there's no reason you could create the component is
VB/C++ if you're more comfortable in those environments. You would also see
a performance gain as componenets in those languages would be precompiled.

What a trainwreck! That should read, "...there's no reason you COULDN'T
create the component IN VB/C++ if you're more comfortable in those
environments. You would also see a performance gain as COMPONENTS in those
languages would be precompiled." I really need to get some sleep. :)

-Chris Hohmann
 
J

Jay Kappel

I do that myself all the time as well.. :)

Ok, so how do I get access to the IPersistStreamInit interface that the HTML
Document inplements?

Thanks...
 
C

Chris Hohmann

Jay Kappel said:
I do that myself all the time as well.. :)

Ok, so how do I get access to the IPersistStreamInit interface that the HTML
Document inplements?

You have to go through the QueryInterface method of the IDispatch interface
that HTMLDocument inherits from. Here are two (2) examples from the MSDN
site:

Reusing MSHTML : Loading HTML and Referenced Data:
http://msdn.microsoft.com/library/d...g/hosting.asp?frame=true#Loading_HTML_and_Ref

WebBrowser Control : Loading HTML content from a Stream
http://msdn.microsoft.com/library/d.../browser/webbrowser/tutorials/webocstream.asp
 
Y

Yan-Hong Huang[MSFT]

Hi Jay,

Do you still have any more concerns on this problem? If there is any we can
do for it, please feel free to post here. Thanks.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jay Kappel

Yes, I have been unable to successfully achieve my goal. One additional
thing I tried was creating an instance of IE
server.createobject("InternetExplorer.Application"). It works but for some
reason when I run it on the server it takes like 50 seconds to return. If I
copy and paste the code into VB it takes only 3-4 seconds.

So, I have tired many ways to skin this darn cat.... None are working!
Any help is always appreciated!

Jay Kappel
 
Y

Yan-Hong Huang[MSFT]

Hello Jay,

Have you tried implement those VB 6 code into one ActiveX control and then
use them in your asp code? That could be a workaround for you.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jay Kappel

I have done that. I created an ActiveX dll in VB and used the code in
there. For whatever reason, I still found that there was quite a delay in
the readystate of ie completing.

Also, I tried the approach using the microsoft html object library. With
this approach, it works awesome when I call the dll from a vb application,
but does not work at all when called from ASP. Any Ideas?

Thanks.
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top