I've got a site up and working well with Google Maps and am now
implementing error handling logic.  I'm starting with trying to sense
when my xml is badly formed.

When I'm using GXmlHttp in Internet Explorer 8, the
responseXML,documentElement is always null so I run the responseText
through GXml.parse.  If the documentElement is still null, I know the
xml is malformed - ok so far.

On Firefox 3, the responseXML.documentElement is ready for use
(assuming the xml was ok).  But what I cannot figure out is how to
catch any errors.  The FF error console produces the expected
"mismatched tag" error but I'm not able to catch it in my code.

This is what I'm trying:


function getXml(xmlFileName) {
        /***
        *  Get a file's parsed xml node synchronously (by using false on the
open)
        *  which means we'll hang here until the data is retrived.
        *
        *  TODO: get error handling to work
        *
        *  It appears that request.responseXML is set up in FireFox 3 but not
        *  in IE 8.
        *
        *  I'm intentionally passing some messed up xml and trying to trap
the
        *  error.  In IE, this results in a null documentElement, but there
is
        *  nothing I have tried that will catch the error in FF.
        ***/
        var trace = (xmlFileName == "map-data/Gotos.xml");

        if (trace) alert(1);
        try {
                var request = GXmlHttp.create();
                request.open("GET", xmlFileName, false);
                request.send(null);
        } catch (error) {
                // this never happens, even when FF reports a 'mismatched tag'
                // error between alert 1 & alert 2
                alert ("When reading xmlFileName:\n" + error.description);
                return null;
        }
        if (trace) alert(2);


        if (trace) {
                dumpObjectProperties(request);
                dumpObjectProperties(request.responseXML);
        }


        try {
                var xml = request.responseXML;
        } catch (error) {
                // never happens
                alert ("2When reading xmlFileName:\n" + error.description);
                return null;
        }


        if (!xml.documentElement) {
                // this always happens in IE 8
                xml = GXml.parse(request.responseText);
        }

        if (!xml.documentElement) {
                // this is only working for IE
                alert(xmlFileName + " is not in the correct format.");
                return null;
        }
        return xml;
}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to