Link to home
Start Free TrialLog in
Avatar of 145cfc
145cfc

asked on

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.
Avatar of sybe
sybe

If xml.documentElement.childNodes.length > 0 Then

Avatar of 145cfc

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Rejojohny
Rejojohny
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
any particular reason for a grade B ..
Avatar of 145cfc

ASKER

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.
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 ..
Avatar of 145cfc

ASKER

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

Thx ... u could ask for corecting the grade by posting a question in the comunity support
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 ...
so r u going to post a request to change the grade ...just inquiring ...
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 ...
Avatar of 145cfc

ASKER

No problem at all! Thank you for your answer - and congrats on the certificate!