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.2.1.2.9, 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>'
$oXMLDOM.loadXML($xml)
$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
You could use IsObj()
to test if a valid object was returned:
If Not IsObj($oNode) Then
MsgBox(0, 'ERROR', 'Node is invalid!')
EndIf