Check if element exists in XML file in ASP

I'm running a site to which multiple clients send XML files on a short interval basis. These XML-files are being parsed using an ASP-page that refreshes every 30 seconds.

When the refresh happens while a transfer from a client is in progress I get this error:
----------------------------------------------------------
Microsoft VBScript runtime error '800a01a8'

Object required: ''
----------------------------------------------------------

I get the items from the XML-file using this code (as I know specifically the layout of the incoming XML-files):

strperiode = xml.documentElement.childNodes(0).text

My last elements is #26 - but how do I check that that element exist eg:

str_temp = xml.documentElement.childNodes(26).text

does not fail because the upload from the client is in progress? If the element does not exist I simply ignore this XML-file for the next 30 seconds - no harm done in that! But I need to know how to check for this element before trying to get it from the XML-file.
145cfcAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RejojohnyConnect With a Mentor Commented:
what about
xml.documentElement.childNodes(26) is nothing

or does item 26 have s unique tag name .. if s, then u could the method "getelementsbytagname" ...
0
 
sybeCommented:
If xml.documentElement.childNodes.length > 0 Then

0
 
145cfcAuthor Commented:
Hi sybe - fraid it aint enough. Haven't tested it yet though and will of course. But some of the elemenst appear to be in the file even though its being uploaded from the client - thats why I specifically want to know if item 26 exists as it is the last element in the file!

Thank you.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
RejojohnyCommented:
any particular reason for a grade B ..
0
 
145cfcAuthor Commented:
well - your answer guided me in the right direction but I wasn't able to implement it directly. It did guide me to another solution though so you were coaching me insted of providing me with the answer.

Since this is my first question on EE ever I read the grading guidelines and finally determined to put in the B-grade. If it is wrong based on my above explanation please do correct me.
0
 
RejojohnyCommented:
ok . no problem .. but then could u also post ur final solution, so that any other person refrering to this thread will have a ready solution instead of re-inventing the wheel ..
0
 
145cfcAuthor Commented:
Excellent suggestion. Thank you. (and btw I realise that I did indeed use your suggestion - my fault! Can I in any way correct your grade?)

I came up with this solution to my problem (and it may be a bit overkill but being good at ASP and not so good at XML this works fine for me as of now):

Set objXML = Server.CreateObject("Microsoft.XMLDOM")
Set objLst = Server.CreateObject("Microsoft.XMLDOM")

objXML.async = False
objXML.Load (Server.MapPath("filename"))

Set objLst = objxml.getElementsByTagName("elementname")
if  objLst.Length = 1 then
 'execute your code
end if

0
 
RejojohnyCommented:
Thx ... u could ask for corecting the grade by posting a question in the comunity support
0
 
RejojohnyCommented:
BTW, this line is not reqd ...
Set objLst = Server.CreateObject("Microsoft.XMLDOM")

the rest is not an overkill and u will have to do it that way ...
0
 
RejojohnyCommented:
so r u going to post a request to change the grade ...just inquiring ...
0
 
145cfcAuthor Commented:
0
 
RejojohnyCommented:
sorry & thx .. this will ensure that i get the masters certifcate in the ASP section .. was short by just 400 points :-) hope u didn't mind me pursuing u this way ...
0
 
145cfcAuthor Commented:
No problem at all! Thank you for your answer - and congrats on the certificate!
0
All Courses

From novice to tech pro — start learning today.