Discussion:
MSXML4 and selectSingleNode
(too old to reply)
Marja Ribbers-de Vroed
2006-02-13 12:35:14 UTC
Permalink
The following is a code snippet of a classic ASP webapplication:

Set l_oNode = p_oXML.selectSingleNode(l_sXPath)
If (Not IsNull(l_oNode)) Then
l_sValue = l_oNode.text
End If

According to http://www.devguru.com/Technologies/xmldom/quickref/node_selectSingleNode.html the selectSingleNode method should return Null when no node was found for the XPath expression, but it doesn't. At least not in a way that satisfies the "Not IsNull()" test.

The program always tries to execute l_sValue = l_oNode.text which obviously results in errors when the node was not found.

What am I missing?
--
Marja
Martin Honnen
2006-02-13 12:54:15 UTC
Permalink
Post by Marja Ribbers-de Vroed
Set l_oNode = p_oXML.selectSingleNode(l_sXPath)
If (Not IsNull(l_oNode)) Then
l_sValue = l_oNode.text
End If
With VBScript the value returned is Nothing so you need to check e.g.
If Not l_oNode Is Nothing Then
' access node here
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Marja Ribbers-de Vroed
2006-02-13 13:16:02 UTC
Permalink
Post by Martin Honnen
With VBScript the value returned is Nothing so you need to check e.g.
If Not l_oNode Is Nothing Then
' access node here
Thanks, that worked.

I'm still somewhat puzzled though, because IsObject(l_oNode) also returned True even when the node was not found by selectSingleNode.
Do you have any idea why?

--
Marja
Martin Honnen
2006-02-13 14:10:06 UTC
Permalink
Post by Marja Ribbers-de Vroed
I'm still somewhat puzzled though, because IsObject(l_oNode) also
returned True even when the node was not found by selectSingleNode.
Do you have any idea why?
That is how VBScript works, the special value Nothing is defined to
behave that way.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Marja de Vroed
2006-02-13 16:57:37 UTC
Permalink
Post by Martin Honnen
That is how VBScript works, the special value Nothing is defined to
behave that way.
So the value Nothing is an object in VBscript?
--
Marja
Loading...