parseError.reason Mozilla equivalent

S

Sebastian Feher

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
 
S

sfeher

Sebastian said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top