Skip to content

Instantly share code, notes, and snippets.

@ehynds
Created August 27, 2010 13:37
Show Gist options
  • Save ehynds/553364 to your computer and use it in GitHub Desktop.
Save ehynds/553364 to your computer and use it in GitHub Desktop.
// based heavily off:
// https://sites.google.com/a/van-steenbeek.net/archive/explorer_domparser_parsefromstring
if( typeof window.DOMParser === "undefined" ){
window.DOMParser = function(){};
window.DOMParser.prototype.parseFromString = function(str, contentType){
if(typeof ActiveXObject !== 'undefined'){
var xmldata = new ActiveXObject('MSXML.DomDocument');
xmldata.async = false;
xmldata.loadXML(str);
return xmldata;
} else if(typeof XMLHttpRequest !== 'undefined'){
var xmldata = new XMLHttpRequest;
if(!contentType){
contentType = 'application/xml';
}
xmldata.open('GET', 'data:' + contentType + ';charset=utf-8,' + encodeURIComponent(str), false);
if(xmldata.overrideMimeType) {
xmldata.overrideMimeType(contentType);
}
xmldata.send(null);
return xmldata.responseXML;
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment