Jump to content
Sign in to follow this  

How to handle failed XPATH lookup in MSXML from AutoIT?

Recommended Posts

I am parsing a piece of XML returned from a Web API. I am looking for a particular node. If that node does not exist, according to the MSXML documentation, it returns null.
The problem is, I don't know how to check for null in AutoIT. I have read the online API doc for Null, but when I run the script using AutoIt3Wrapper v., it does not recognize null.
Here is a sample script to show what I mean:
$oXMLDOM = ObjCreate("Msxml2.DOMDocument.3.0")
$xml = '<response><error code="1"><![CDATA[ Incorrect password or username ]]></error></response>'
$node = $oXMLDOM.selectSingleNode("/response/error")
MsgBox(0, "", $node.text) ;; No problems
$node = $oXMLDOM.selectSingleNode("/response/token")
;; $node should be 'null' now; how do I check that in AutoIT?
MsgBox(0, "", $node.text) ;; Fails horribly


Share this post

Link to post
Share on other sites

OK, well, I have kind of found a quick workaround for my problem.

By using ObjName, I can check the name of the COM object returned, which is IXMLDOMElement if it is successful:

If ObjName($node) = "IXMLDOMElement" Then
    MsgBox(0, "", "Success")
    MsgBox(0, "", "Failure")

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.