
function getDocumentObjectFromString(xmlString) {
        if (document.implementation && document.implementation.createDocument) { 
          //  alert(1);
                // Mozilla, Firefox, and related browsers 
                return (new DOMParser()).parseFromString(xmlString, "application/xhtml+xml"); 
            } 
            else if (typeof ActiveXObject != undefined) { 
            //    alert(2);
                // Internet Explorer. 
                // var doc = XML.newDocument();  // Create an empty document 
                var doc = new ActiveXObject("Microsoft.XMLDOM"); 
                doc.async = false;
                doc.loadXML(xmlString);            // Parse text into it 
                //var pi = doc.createProcessingInstruction("xml"," version='1.0' encoding='UTF-8'");
                //doc.appendChild(pi);
                
                return doc;                   // Return it 
            } 
            else { 
             //   alert(3);
                // As a last resort, try loading the document from a data: URL 
                // This is supposed to work in Safari. Thanks to Manos Batsis and 
                // his Sarissa library (sarissa.sourceforge.net) for this technique. 
                var url = "data:text/xml;charset=utf-8," + encodeURIComponent(xmlString); 
                var request = new XMLHttpRequest(); 
                request.open("GET", url, false); 
                request.send(null); 
                return request.responseXML; 
            } 
}
