Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monolithed/1c988207c7120596f603 to your computer and use it in GitHub Desktop.
Save monolithed/1c988207c7120596f603 to your computer and use it in GitHub Desktop.
/*globals DOMImplementation, ActiveXObject */
if (!DOMImplementation.prototype.createDocument) {
(function () {
'use strict';
var i, docObj, docObjType,
docObjs = [
'MSXML6.DOMDocument', 'MSXML5.DOMDocument', 'MSXML4.DOMDocument',
'MSXML3.DOMDocument', 'MSXML2.DOMDocument.5.0', 'MSXML2.DOMDocument.4.0',
'MSXML2.DOMDocument.3.0', 'MSXML2.DOMDocument', 'MSXML.DomDocument',
'Microsoft.XmlDom'
],
dol = docObjs.length;
for (i=0; i < dol; i++) {
try {
docObj = new ActiveXObject(docObjs[i]);
docObjType = docObjs[i]; // Set this after ActiveXObject to ensure only set if no errors thrown
break;
}
catch (e) {
}
}
/**
* This shim implementation does not provide any support for doctype, nor does it wrap the resulting
* document so as to support all current DOM methods and properties
*/
DOMImplementation.prototype.createDocument = function (namespace, qualifiedName, doctype) {
if (doctype) {
throw 'This is not a complete shim for ' +
'DOMImplementation.prototype.createDocument.';
}
if (!docObjType) {
throw 'Could not create a DOM document object';
}
var pos, prefix,
prefixedNs = '',
doc = new ActiveXObject(docObjType);
if (qualifiedName) {
pos = qualifiedName.indexOf(':');
if (pos > -1) {
prefix = qualifiedName.slice(0, pos);
prefixedNs = ' xmlns:' + prefix + '="' + namespace + '"';
}
else if (namespace) {
prefixedNs = ' xmlns="' + namespace + '"';
}
doc.loadXML('<' + qualifiedName + prefixedNs + '/>');
}
return doc;
};
}());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment