Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determine null record in XML in classic asp

Status
Not open for further replies.

guestAsh

Technical User
Feb 27, 2004
65
GB
Appogies if this is in the wrong forum, wasn't to sure if to post here or in asp forum?

I've got this function,

Code:
Function yellowpages(strXMLFile, strXSLFile, strSid)
 'Declare local variables
 Dim objXML
 Dim objNode
 Dim objXSL
 'Instantiate the XMLDOM Object that will hold the XML file.
 set objXML = Server.CreateObject("Microsoft.XMLDOM")
 'Turn off asyncronous file loading.
 objXML.async = false
 'Load the XML file.
 objXML.load(strXMLFile)
 'Get the XML record that you wish to view by calling the
 'SelectSingleNode method and passing in the e-mail address of the
 'contact.
 Set objNode = objXML.SelectSingleNode("rolodex/contact[field/field_value='" & strSid & "']")
 'Instantiate the XMLDOM Object that will hold the XSL file.
 set objXSL = Server.CreateObject("Microsoft.XMLDOM")
 'Turn off asyncronous file loading.
 objXSL.async = false
 'Load the XSL file.
 objXSL.load(strXSLFile)
 'Use the "transformNode" method of the XMLDOM to apply the XSL
 'stylesheet to the XML document. Then the output is written to the
 'client.
 Response.Write(objNode.transformNode(objXSL))
 
End Function

that looks at the record in the xml file which matches a request.querystring("sid"), but if the "sid" doesn’t match any record in the xml, I get the following error:
Code:
Microsoft VBScript runtime error '800a01a8' 
Object required: 'objNode' 
/PU/about/yellowpages/rolodex6.asp, line 290

Is there a test I can do to make sure the record exists or not?

i've tried doing the following, but it dosn't work?

Code:
If objXML.SelectSingleNode("rolodex/contact[field/field_value='" & strSid & "']") Then
	Set objNode = objXML.SelectSingleNode("rolodex/contact[field/field_value='" & strSid & "']")
	' Rest of the transforming
	Response.Write objNode.transformNode(objXSL)
End If


any help will be greatly appriciated

thanks

Ash
 
The test you want to have is this.
[tt]
'etc etc
Set objNode = objXML.SelectSingleNode("rolodex/contact[field/field_value='" & strSid & "']")

[green]if objNode is nothing then
'SelectSingleNode fails to select any
'do something for this case
else[/green]
'do what you are doing or trying to do
'etc etc
[green]end if[/green]
[/tt]
 
Thanks tsuji,

Thats great, thanks again for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top