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.childN odes(0).te xt
My last elements is #26 - but how do I check that that element exist eg:
str_temp = xml.documentElement.childN odes(26).t ext
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.
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.childN
My last elements is #26 - but how do I check that that element exist eg:
str_temp = xml.documentElement.childN
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.
If xml.documentElement.childN odes.lengt h > 0 Then
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.
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
any particular reason for a grade B ..
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.
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 ..
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("Micro soft.XMLDO M")
Set objLst = Server.CreateObject("Micro soft.XMLDO M")
objXML.async = False
objXML.Load (Server.MapPath("filename" ))
Set objLst = objxml.getElementsByTagNam e("element name")
if objLst.Length = 1 then
'execute your code
end if
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("Micro
Set objLst = Server.CreateObject("Micro
objXML.async = False
objXML.Load (Server.MapPath("filename"
Set objLst = objxml.getElementsByTagNam
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("Micro soft.XMLDO M")
the rest is not an overkill and u will have to do it that way ...
Set objLst = Server.CreateObject("Micro
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 ...
ASKER
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 ...
ASKER
No problem at all! Thank you for your answer - and congrats on the certificate!