Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts

    XML-file not found - warning

    Hi,

    Using the standard methode for IE, like

    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.validateOnParse="false";
    xmlDoc.load("somefile.xml");
    xmlDoc.readyState==4
    etc.

    The file - something.xml - is found read-out etc.

    My question is:

    When this file - something.xml - is not been found (wrong filename or other reasons) I like to have an alert.
    In other words a - file not found - warning

    How should I do this?

    Thanks,
    Jerome

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,459
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Hm. I don't work much with IE, but do you ever get a script error if it's 404?

    Perhaps a try...catch statement would help, if you do.
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Use xmlDoc.status to find out the status code as per RFC2616. 200 and possibly 202 are what you want. The others you can either give the same message or write custom error messages for.

    Remember that XMLHTTPRequest can't reach out of the current domain - wrap a try..catch clause around it to cure that problem.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #4
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Liorean,

    XMLHTTP has the possibility of:

    status (which is a code like '200' as you mentioned)

    but also

    statusText (which gives You an 'OK')

    I tried this with XMLDOM as well, but that doesn't seem to work!

    Maybe a strange question, but when I use the XMLHTTP methode like:

    var objHTTP = new ActiveXObject("Microsoft.XMLHTTP")
    objHTTP.Open('GET','somefile.xml',false)
    objHTTP.Send()
    alert(objHTTP.status)
    alert(objHTTP.statusText)
    alert(objHTTP.responseText)

    Does it only work on the net, not locally, like XMLDOM?
    (I get a warning that I use an incorrect parameter!)

    Thanks for Your ideas,
    Jerome

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    XMLDOM doesn't behave exactly as XMLHTTP - you can rely on XMLHTTP in far more situations than XMLDOM. Same goes for moz equivalents.

    Do you mean the non-existent page gives a status of 200 (OK)? That is clearly wrong.


    XMLHTTP works on file: protocol too, but the file protocol doesn't send http headers, nor does it send an http status code.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What I understand is that I should use XMLHTTP instead of XMLDOM. But XMLHTTP = not w3c standard , how about the future? Since to my idea more and more people use xml-files, which protocol is going to servive and maybe more important which browser manufac. are going to use this protocol. Or do You think that because of security the import of files will be restricted, abandont!

    You quoted:"Do you mean the non-existent page gives a status of 200 (OK)? That is clearly wrong."

    status==200:
    http://www.w3schools.com/dom/tryit.a...try_dom_status

    statusText==OK;
    http://www.w3schools.com/dom/tryit.a...dom_statustext

    XMLDOM locally works well, without warning:

    var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.validateOnParse="false";
    xmlDoc.load("somefile.xml");
    xmlDoc.readyState==4
    etc.

    XMLHTTP, however gives a warning:

    var objHTTP = new ActiveXObject("Microsoft.XMLHTTP")
    objHTTP.Open('GET','somefile.xml',false)
    objHTTP.Send()
    alert(objHTTP.status)
    alert(objHTTP.statusText)
    alert(objHTTP.responseText)

    The warning "incorrect parameter" is from: objHTTP.Open('GET','somefile.xml',false), not: objHTTP.Send() can I assume that it should work when uploaded?

    Jerome

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Upload it and test it. I've found that there are multiple strange quirks that differ locally versus uploaded.

    Only a page that is found/accessible should give 200 (OK) response - a not found page should give some 400 response.
    Last edited by liorean; 04-28-2003 at 01:41 PM.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #8
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Originally posted by Jerome
    What I understand is that I should use XMLHTTP instead of XMLDOM. But XMLHTTP = not w3c standard
    But ActiveXObject("Microsoft.XMLDOM") is a standard? Definitely not.

    Using the W3C DOM3 Load & Save interface (in Working Draft status), you'd use:
    var newDoc = document.implementation.createDocument('', null,null);
    newDoc.load("somefile.xml");

    Mozilla can do this. However, because it is not in Candidate Recommendation status yet, this is not a web standard yet. There exists no standard to do this entirely in script. What you can do is dynamically append an iframe to the body, and use that as an xml loader by changing its source, and getting the document by refToIframe.contentDocument

  • #9
    Regular Coder
    Join Date
    Oct 2002
    Posts
    299
    Thanks
    0
    Thanked 0 Times in 0 Posts
    jkd,

    Thanks, but for the moment I will stay with the combined Mozilla/XMLDOM solution I have. This replaces my old load document in iframe solution.

    Only wondering if XMLHTTP comes in favor of XMLDOM like to my idea Liorean thinks.

    Jerome


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •