...

View Full Version : XML-file not found - warning



Jerome
04-27-2003, 07:53 PM
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

Alex Vincent
04-27-2003, 09:38 PM
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.

liorean
04-27-2003, 09:46 PM
Use xmlDoc.status to find out the status code as per RFC2616 (http://www.ietf.org/rfc/rfc2616.txt). 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.

Jerome
04-28-2003, 11:30 AM
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

liorean
04-28-2003, 12:12 PM
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.

Jerome
04-28-2003, 01:08 PM
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.asp?filename=try_dom_status

statusText==OK;
http://www.w3schools.com/dom/tryit.asp?filename=try_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

liorean
04-28-2003, 01:30 PM
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.

jkd
04-28-2003, 03:58 PM
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

Jerome
05-03-2003, 10:27 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum