AJAX with XML, without proper response headers.

One of my clients is dealing with an antiquated Lotus Notes 5.1 database for storing files, and I was asked to build an AJAX interface that would pull a list of files filtered by Category onto an HTML page. The Lotus Notes wizards were able to build an XML "view" of the files, which listed all of the files associated with a Document, however they weren't able to set the Content-Type of the response to "text/xml". This means that the standard XMLHttpRequest in both Internet Explorer and Gecko don't populate the "responseXML" property with the parsed XML document.

I also noted that the way in which the responseXML failed to be populated differed from browser to browser. In Internet Explorer 6.1, the responseXML.documentElement wasn't populated, but in Gecko, the responseXML wasn't populated.

So, I wrote a short snippet to handle responses which don't have the proper Content-Type header set:

function onXMLHttpLoad( objXMLHttp) {
    // First try to use the auto-parsed value
    var xml = objXMLHttp.responseXML;
    // The browser failed, but we think we're smarter
    if( !xml || !xml.documentElement ) {
        // Internet Explorer, use the Msxml COM object
        if( window.ActiveXObject ) {
            xml = new ActiveXObject( "Msxml2.DOMDocument" );
            xml.loadXML( objXMLHttp.responseText );
        } else if ( DOMParser ) { // Use the gecko builtin if it's available.
            xml = new DomParser().parseFromString(objXMLHttp.responseText, "text/xml" );