Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions m-xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ THE SOFTWARE.
}

function loadXML(source) {
var xhr = (window.ActiveXObject || "ActiveXObject" in window) ?
new ActiveXObject("Msxml2.XMLHTTP.3.0") :
new XMLHttpRequest();
if (isXML(source)) {
return parseXMLString(source);
}
else {
var xhr = new XMLHttpRequest();

xhr.open("GET", source, false);
xhr.send();
return xhr.responseXML;
xhr.open("GET", source, false);
xhr.send();
return xhr.responseXML || parseXMLString(xhr.responseText);
}
}

function parseXMLString(xmlString) {
Expand Down Expand Up @@ -101,7 +104,12 @@ THE SOFTWARE.
if (window.ActiveXObject || "ActiveXObject" in window) {
var xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument.6.0");
xsl.async = false;
xsl.load(source);
if (isXML(source)) {
xsl.loadXML(source);
}
else {
xsl.load(source);
}
return xsl;
}

Expand Down Expand Up @@ -187,10 +195,8 @@ THE SOFTWARE.
/// compatability issues automatically.
/// </summary>
transform: function (xmlSource, xslSource, parameters) {
var xml = (isXML(xmlSource)) ? parseXMLString(xmlSource)
: loadXML(xmlSource),
xsl = (isXML(xslSource)) ? parseXMLString(xslSource)
: loadXSL(xslSource);
var xml = loadXML(xmlSource),
xsl = loadXSL(xslSource);

if (window.ActiveXObject || "ActiveXObject" in window) {
return getActiveXTransform(xml, xsl, parameters);
Expand All @@ -215,7 +221,12 @@ THE SOFTWARE.
}

if (window.ActiveXObject || "ActiveXObject" in window) {
target.innerHTML = transformed;
var node = document.createElement('div');
node.innerHTML = transformed;
Array.prototype.slice.call(node.childNodes, 0).forEach(function (nd) {
target.parentNode.insertBefore(nd, target);
});
target.parentNode.removeChild(target);
}
else {
target.parentNode.replaceChild(transformed, target);
Expand Down