[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Check if element exists in XML file in ASP

Posted on 2004-10-23
15
Medium Priority
?
425 Views
Last Modified: 2013-11-19
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.
0
Comment
Question by:145cfc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
15 Comments
 
LVL 28

Expert Comment

by:sybe
ID: 12387971
If xml.documentElement.childNodes.length > 0 Then

0
 

Author Comment

by:145cfc
ID: 12387980
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
 
LVL 26

Accepted Solution

by:
Rejojohny earned 2000 total points
ID: 12392498
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Expert Comment

by:Rejojohny
ID: 12398092
any particular reason for a grade B ..
0
 

Author Comment

by:145cfc
ID: 12398113
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12398123
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
 

Author Comment

by:145cfc
ID: 12398146
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12398150
Thx ... u could ask for corecting the grade by posting a question in the comunity support
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12398156
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12398231
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
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12398570
so r u going to post a request to change the grade ...just inquiring ...
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 12398596
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
 

Author Comment

by:145cfc
ID: 12398611
No problem at all! Thank you for your answer - and congrats on the certificate!
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question