PDA

View Full Version : DOM - Finding node problem - VB


Number_Nineteen
08-03-2004, 05:39 PM
Hi,
I am trying to check for the existence of a node. If the node is found, I do nothing. If it is not found, I want to insert the node. So, I want to execute the if statement based on the result of that check. My code below errors because the node (objProd) is not found. What is the proper way to say "if the node is null", so I can then insert the node?


'THESE NODES RESOLVE
Set objRoot = objXML.documentElement
Set objItem = objRoot.SelectSingleNode("item[@name='" & cat & "']")
Set objSub = objItem.SelectSingleNode("sub[@name='" & subcat & "']")
'PROBLEM AREA BELOW
Set objProd = objSub.SelectSingleNode("product[@id='" & id & "']") 'THIS DOES NOT RESOLVE
Set theValue = objProd.getAttributeNode("id")

'THIS ERRORS BECAUSE 'objProd' IS NOT FOUND
if theValue.text <> "" then

Response.write "<font color='red'><strong>That product already exists in this category.</strong></font></font>"

else
Set objField = objXML.createElement("product")
Set objattID = objXML.createAttribute("id")

objattID.Text = id

objField.setAttributeNode objattID
objProd.appendChild objField

objXML.save strXMLFile
end if