parseError.reason Mozilla equivalent

Discussion in 'Javascript' started by Sebastian Feher, Jul 25, 2006.

  1. 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
    Sebastian Feher, Jul 25, 2006
    #1
    1. Advertising

  2. Sebastian Feher

    Guest

    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
    , Jul 25, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ted
    Replies:
    1
    Views:
    578
    Eric Lawrence [MSFT]
    Mar 1, 2004
  2. Henri
    Replies:
    9
    Views:
    1,800
    Toby Inkster
    Feb 22, 2005
  3. Farshid

    2to3 ParseError with UTF-8 BOM

    Farshid, Nov 5, 2009, in forum: Python
    Replies:
    3
    Views:
    568
    Gabriel Genellina
    Nov 13, 2009
  4. Red_Indian

    Equivalent of .disabled = false in Mozilla?

    Red_Indian, May 11, 2004, in forum: Javascript
    Replies:
    6
    Views:
    119
  5. Mark Szlazak
    Replies:
    6
    Views:
    142
    Csaba Gabor
    Mar 14, 2005
Loading...

Share This Page