|
Microsoft have provided a self-installing
CAB file for the MSXML4.0 parser, along with a sample <OBJECT> Tag
that illustrates how to automatically install this on the client .
By combining this code inside the catch()
section of a Javascript structured exception handling block, it is a simple
matter to test to see if the component is already installed, and if not,
to write the required code dynamically which will cause the browser to
download and install the CAB.
Here's some sample code that tests for
the presence of MSXML4.0, and if it is not present, installs it transparently:
<script language="JavaScript"
>
var XMLDoc = "<?xml version=\"1.0\"?><STUFF>My
Cool XML</STUFF>";
// Msxml2.DOMdocument.4.0
try{
var domDoc = new ActiveXObject("Msxml2.DOMdocument.4.0");
domDoc.async=false;
if (domDoc.loadXML(XMLDoc))
document.write("<INPUT TYPE=CHECKBOX DISABLED CHECKED>Msxml2.DOMdocument.4.0
</INPUT></BR>");
}
catch (e){
document.write("<INPUT TYPE=CHECKBOX DISABLED>Msxml2.DOMdocument.4.0</INPUT>
| "+ e.description +"</BR>");
}
document.write("<object id=\"MSXML4\" classid=\"clsid:88d969c0-f192-11d4-a65f-0040963251e5\"
codebase=\"msxml4.cab#version=8,00,7820,0\" type=\"application/x-oleobject\"
STYLE=\"display: none\"></object>");
</Script>
|
What we are doing here is creating a small
XML document string, and then we try to create the MSXML2.DomDocument.4.0
instance and load the XML document. If the component is there, we can
write out a checkbox (as shown) to indicate that it is installed.
If it is not installed, the method will
fail and our catch( ) block is executed. At the end we simply Response.write
out the object tag, making sure to set the codebase attribute to the exact
location of our CAB file, and Voila! our MSXML4 gets installed.
Peter Bromberg is an independent consultant specializing in distributed .NET solutionsa Senior Programmer
/ Analyst at in Orlando and a co-developer of the EggheadCafe.com
developer website. He can be reached at pbromberg@yahoo.com
|