
detecting "object required" or null object
set obj = CreateObject("MSXML.DOMDocument")
obj.loadXML("<test><hello>bye</hello></test>")
set nodeobj = obj.selectSingleNode("test/hello")
if not (nodeobj Is Nothing) then
msgbox "1) it worked..."
else
msgbox "1) it didn't..."
end if
set nodeobj = obj.selectSingleNode("test/xxxx")
if not (nodeobj Is Nothing) then
msgbox "2) it worked..."
else
msgbox "2) it didn't..."
end if
--
Michael Harris
Microsoft.MVP.Scripting
--
Please do not email questions - post them to the newsgroup instead.
--
Quote:
> Hi,
> I'm using the XML DOM from vbscript and I want to detect whether
> selectSingleNode()
> has returned an object or not. e.g. the following code works fine but how
> do I know if "nodeobj" is a valid object ? If you change the pattern search
> to "test/xxx"
> then MsgBox line fails with "object required".
> Thanks
> set obj = CreateObject("MSXML.DOMDocument")
> obj.loadXML("<test><hello>bye</hello></test>")
> set nodeobj = obj.selectSingleNode("test/hello") // change search
> pattern to "test/xxxx" to get error
> MsgBox nodeobj.text
> set nodeobj = nothing
> set obj = nothing