Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

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

194 views
Skip to first unread message

Jay Kappel

unread,
Apr 30, 2004, 12:16:37 PM4/30/04
to
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@yy@Z

unread,
Apr 30, 2004, 12:35:06 PM4/30/04
to
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
%>


"Jay Kappel" <ja...@paramountfarming.com> wrote in message
news:OTf1w5s...@TK2MSFTNGP11.phx.gbl...

Jay Kappel

unread,
Apr 30, 2004, 12:49:35 PM4/30/04
to
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!


"F@yy@Z" <fayyaz...@mvwebmaker.com> wrote in message
news:elXLkDt...@TK2MSFTNGP09.phx.gbl...

Bob Barrows [MVP]

unread,
Apr 30, 2004, 1:42:16 PM4/30/04
to
Jay Kappel wrote:
> 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&threadm=%23mgwkSWXBHA.1608%40tkmsftngp05&rnum=6&prev=/groups%3Fq%3DMSHTML.HTMLDocument%2520ASP%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26c2coff%3D1%26sa%3DN%26tab%3Dwg

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Bob Barrows [MVP]

unread,
Apr 30, 2004, 1:45:21 PM4/30/04
to

Jay Kappel

unread,
Apr 30, 2004, 2:04:38 PM4/30/04
to
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...


"Bob Barrows [MVP]" <reb0...@NOyahoo.SPAMcom> wrote in message
news:e7w49ptL...@tk2msftngp13.phx.gbl...

Jay Kappel

unread,
Apr 30, 2004, 2:05:23 PM4/30/04
to
Thanks again... This control however does not provide a DOM object, just a
means of getting the http code.

Jay Kappel

"Bob Barrows [MVP]" <reb0...@NOyahoo.SPAMcom> wrote in message

news:uPXCsrtL...@tk2msftngp13.phx.gbl...

Jay Kappel

unread,
Apr 30, 2004, 5:57:42 PM4/30/04
to
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


"Jay Kappel" <ja...@paramountfarming.com> wrote in message
news:OTf1w5s...@TK2MSFTNGP11.phx.gbl...

Yan-Hong Huang[MSFT]

unread,
May 2, 2004, 10:14:59 PM5/2/04
to
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.

Chris Hohmann

unread,
May 3, 2004, 2:59:02 AM5/3/04
to
"Jay Kappel" <ja...@paramountfarming.com> wrote in message
news:euSIX4vL...@TK2MSFTNGP12.phx.gbl...

> 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. Baute

unread,
May 3, 2004, 3:13:00 AM5/3/04
to
"Jay Kappel" <ja...@paramountfarming.com> wrote in message news:<OTf1w5s...@TK2MSFTNGP11.phx.gbl>...

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.

Jay Kappel

unread,
May 3, 2004, 11:53:53 AM5/3/04
to
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" <nos...@thankyou.com> wrote in message
news:e%23o22qNM...@TK2MSFTNGP11.phx.gbl...

Chris Hohmann

unread,
May 3, 2004, 1:33:44 PM5/3/04
to
"Jay Kappel" <ja...@paramountfarming.com> wrote in message
news:%23QM$DbSMEH...@tk2msftngp13.phx.gbl...

> 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

Chris Hohmann

unread,
May 3, 2004, 1:45:18 PM5/3/04
to

"Chris Hohmann" <nos...@thankyou.com> wrote in message
news:%2366FfNT...@TK2MSFTNGP09.phx.gbl...

> 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


Jay Kappel

unread,
May 3, 2004, 2:09:13 PM5/3/04
to
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...

"Chris Hohmann" <nos...@thankyou.com> wrote in message

news:eOho8TTM...@TK2MSFTNGP09.phx.gbl...

Chris Hohmann

unread,
May 3, 2004, 3:23:42 PM5/3/04
to
"Jay Kappel" <ja...@paramountfarming.com> wrote in message
news:ucHBsmTM...@TK2MSFTNGP12.phx.gbl...

> 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/default.asp?url=/workshop/browser/hosting/hosting.asp?frame=true#Loading_HTML_and_Ref

WebBrowser Control : Loading HTML content from a Stream
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/tutorials/webocstream.asp

Yan-Hong Huang[MSFT]

unread,
May 4, 2004, 10:11:38 PM5/4/04
to
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.

Jay Kappel

unread,
May 5, 2004, 7:45:08 PM5/5/04
to
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

"Yan-Hong Huang[MSFT]" <yhh...@online.microsoft.com> wrote in message
news:6vKIQZkM...@cpmsftngxa10.phx.gbl...

Yan-Hong Huang[MSFT]

unread,
May 5, 2004, 10:44:25 PM5/5/04
to
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.

Jay Kappel

unread,
May 6, 2004, 11:54:19 AM5/6/04
to
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.

"Yan-Hong Huang[MSFT]" <yhh...@online.microsoft.com> wrote in message

news:7gp4QQxM...@cpmsftngxa10.phx.gbl...

Jay Kappel

unread,
May 6, 2004, 12:39:01 PM5/6/04
to
OK, Here's the latest...

I have an activex dll that does what I need it to do. I have created an
ASP page that uses that dll. On my windows XP Professional machine I have
registered the dll and used my local web server to browse the asp page. The
good news is that it works GREAT! The page completes in 3-4 seconds.
However when I transfer the dll and the ASP page to a Windows Web 2003
server it jumps up to a whopping 54 seconds!

I am wondering if this could have something to do with the enhanced
browsing security implemented by default on the Web Server 2003? It appears
that this enhanced setting is profile based, so setting it back to a normal
level for my admin account does not help the IUSR_MachineName account. Does
anyone know how I can change this setting for the IUSR account? And is
there a registry key or something that I can have my com object change and
then flip back when it's done. Will the com object have the appropriate
security rights to perform this action? And lastly am I barking up the
wrong tree?

Thanks, Jay Kappel


"Yan-Hong Huang[MSFT]" <yhh...@online.microsoft.com> wrote in message

news:7gp4QQxM...@cpmsftngxa10.phx.gbl...

Yan-Hong Huang[MSFT]

unread,
May 6, 2004, 10:38:07 PM5/6/04
to
Hello Jay,

This is quite strange due to the performance drop on Win2003 . If you feel
it is related to IE Enhanced Security Configuration, please uninstall it in
control panel->Add/Remove programs->Add/Remove Windows Components, then
test it again to see if it helps.

Looking at the nature of this issue, it would require intensive
troubleshooting which would be done quickly and effectively with direct
assistance from a Microsoft Support Professional through Microsoft Product
Support Services. I suggest you contact Microsoft Product Support directly
to discuss additional support options you may have available, by contacting
us at 1-(800)936-5800 or by choosing one of the options listed at
http://support.microsoft.com/default.aspx?scid=sz;en-us;top. As a MSDN
subscriber, you have two free support incidents.

0 new messages