MSXML sniffing in VFP

M

Seeing Rino’s blog entry on XML Sniffing reminded me of how common this little gotcha is.

So you might find the following handy. When our apps start up we just run a checkdependencies(bCheckXML3, bCheckXML4, etc) method with something like the following (and can someone tell me how to get code samples looking good on blogger please):

LOCAL cSaveError
LOCAL oObject3, oObject4, cMessage
cMessage = ”

PUBLIC bDependencyError

cSaveError = ON (“ERROR”)

IF NOT EMPTY(cSaveError)
ON ERROR &cSaveError
ENDIF

bDependencyError = .F.

ON ERROR bDependencyError = .T.

IF bCheckXML3
oObject3 = CREATEOBJECT(“MSXML2.DOMDocument.3.0”)
IF TYPE(‘oObject3’) <> ‘O’
cMessage = cMessage + ‘Microsoft XML3 Parser is not initialising. You may need to reinstall this module. ‘ + CHR(13)
ENDIF
ENDIF

IF bCheckXML4
oObject4 = CREATEOBJECT(“MSXML2.DOMDocument.4.0”)
IF TYPE(‘oObject4’) <> ‘O’
cMessage = cMessage + ‘Microsoft XML4 Parser is not initialising. You may need to reinstall this module. ‘ + CHR(13)
ENDIF
ENDIF

IF NOT EMPTY(cMessage)
** do your stuff here eg direct them to Microsoft’s download page etc
http://www.microsoft.com/downloads/details.aspx?FamilyID=C0F86022-2D4C-4162-8FB8-66BFC12F32B0&displaylang=en
or
http://www.microsoft.com/downloads/details.aspx?FamilyID=3144b72b-b4f2-46da-b4b6-c5d7485f2b42&displaylang=en

ENDIF

IF NOT EMPTY(cSaveError)
ON ERROR &cSaveError
ENDIF

oObject3 = .F.
oObject4 = .F.

RELEASE oObject3, oObject4

RELEASE bDependencyError

As Rino says you’ll need MSXML3 for using XMLTOCURSOR. And you’ll need MSXML4 if you’re using ADO calls that use XML.

About Craig

I'm the co-host of HubShots and the CEO of XEN - helping mid-large B2B companies with their digital marketing and lead generation.

Craig Bailey

Archives

Posts