PRB: Testing the Return Value of the selectSingleNode Method in Visual Basic (283803)
The information in this article applies to:
- Microsoft XML 2.0
- Microsoft XML 2.5
- Microsoft XML 2.6
- Microsoft XML 3.0
- Microsoft XML 3.0 SP1
- Microsoft XML 4.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q283803 SYMPTOMS
The MSXML SDK documentation states that the selectSingleNode method of the DOMDocument, IXMLDOMNode, and IXMLDOMElement objects return a NULL if no node that matches the specified query string is found in the loaded XML document. Testing the return value of the selectSingleNode method for a NULL value by using the IsNull() function in Visual Basic returns False even when the method does not return a node that matches the specified query string. Subsequent code that attempts to access the properties and methods of the returned node object based on the return value of the IsNull() conditional test generates the following error message when the selectSingleNode method does not return a matching node:
Run-time error '91' : Object variable or With block variable not set.
CAUSE
A NULL value is an atomic constant that indicates the absence of a value. A NULL value cannot be assigned to object variables by using a Set objvar = Null Visual Basic statement. The selectSingleNode method returns a reference to an IXMLDOMNode object representing the first node that matches the specified query string. In the event of no nodes that match the specified query string, the target IXMLDOMNode object variable to which the result of executing the method is assigned remains uninitialized. It is not assigned a NULL value.
RESOLUTION
Use the Is Nothing conditional expression to test the object variable to which the return value of selectSingleNode is assigned to determine whether a matching node was identified in the loaded XML document.
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 10/12/2001 |
---|
Keywords: | kbDSupport kbprb KB283803 |
---|
|