views:

72

answers:

2

Hi,

For a project I'm doing I have a varied number of nodes with node names of nib"number"_title So I'm using a for loop and within that loop I'm using getElementsByTagName to ge the node but It brings up an error if it's trying to find a node thats not there.

Microsoft VBScript runtime (0x800A01A8) Object required: 'xml.getElementsByTagName(...).item(...)' /newsite/eg/eg.asp, line 46

So how would I test to see if the nodes there and then write it if it is?

My ASP code looks like this:

<% 
Dim i
Dim objTest
For i = 1 to 3
Set objTest = xml.getElementsByTagName("nib"&i&"_title")
if Not (objTest Is Nothing)  Then
 Response.Write("<li><a style=""text-decoration: none; color:white;"" href=""#nib"&i&""">"&xml.getElementsByTagName("nib"&i&"_title").item(0).text&"</a></li>")
End If
Next
%>
A: 

First I'd suggest figuring out how to do debugging using Visual Studio as this will make your life a lot easier (you can inspect your objects while debugging).

Next the problem with the error message is we don't know which "object" VBScript means... does it mean xml, getElementsByTagName(...), or .item(...) which all represent objects you are accessing.

Finally, I would check the length of the NodeList returned by getElementsByTagName as well.

Michael Pryor
Unfortunatly I don't have access to Visual Studio and I'm stuck with Notepad. I'm changing my XML Layout so I can use foreach instead. Thank you for your tips.
Colin Wren
A: 

My XML was flawed. Instead I'm going to put all the nodes I was trying to find into a node so that I can use a foreach loop as this will be easier.

Colin Wren