Sebastian Feher wrote:
Hi All,
I am calling load() on a xml document object and I would like to test
if there was any exception. Is there an equivalent to
xmlDocument.parseError.reason in Mozilla/FF1.5+ ?
So far I've tried to try/catch and tested load return value (nothing
gets returned in FF) for a wrong uri.
Any hints?!
Regards,
Sebastian
Here's the code I have so far:
function importXml(uri, callbackFn )
{
var xmlDoc;
if (document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument('', 'dummy-root',
null);
if (callbackFn)
{
xmlDoc.async = true;
xmlDoc.addEventListener( 'load', callbackFn, false );
var loaded = xmlDoc.load(uri /*, false */);
}
else
{
xmlDoc.async = false;
xmlDoc.load(uri /*, false */);
return xmlDoc;
}
}
else if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.setProperty("SelectionLanguage", "XPath");
if (callbackFn)
{
xmlDoc.async = true;
xmlDoc.onreadystatechange = function ()
{
if (xmlDoc.parseError.errorCode !== 0)
{
throw xmlDoc.parseError.reason + ': ' + xmlDoc.parseError.url;
}
if (xmlDoc.readyState == 4)
{
callbackFn(xmlDoc);
}
};
xmlDoc.load(uri);
}
else
{
xmlDoc.async = false;
var loaded = xmlDoc.load(uri);
if (xmlDoc.parseError.errorCode !== 0)
{
throw xmlDoc.parseError.reason + ': ' + xmlDoc.parseError.url;
}
ASSERT('Xml document not loaded: ' + uri, loaded);
return xmlDoc;
}
}
else
{
throw 'Browser not supported.';
}
}
Currently my code lets me know if there was an error ( e.g. wrong url
for the XML ) in IE and would like to have the same behaviour in FF
also.
I hope this cleared up a bit my intention.
Regards,
Sebastian