Solved

Check if element exists in XML file in ASP

Posted on 2004-10-23
422 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
Question by:145cfc
    14 Comments
     
    LVL 28

    Expert Comment

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

    0
     

    Author Comment

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

    Expert Comment

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

    Author Comment

    by:145cfc
    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
    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
    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
    Thx ... u could ask for corecting the grade by posting a question in the comunity support
    0
     
    LVL 26

    Expert Comment

    by:Rejojohny
    0
     
    LVL 26

    Expert Comment

    by:Rejojohny
    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
    so r u going to post a request to change the grade ...just inquiring ...
    0
     

    Author Comment

    by:145cfc
    0
     
    LVL 26

    Expert Comment

    by:Rejojohny
    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
    No problem at all! Thank you for your answer - and congrats on the certificate!
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

     Java Android Coding Bundle

    Whether you're an Apple user or Android addict, learning to code for the Android platform is an extremely valuable, in-demand skill. It all starts with Java, the language behind the apps and games that make Android the top platform it is today.

    It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
    I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    913 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now