diff --git a/README.md b/README.md index 8b62a61..ccce214 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ You can get the XML result tree: The result object can be accessed also via *oMX.dom* property. The properties available: -- **dom** - result XML DOM object +- **dom** - result XML DOM object - **Note that in older IE browsers this is an ActiveX Object and not a standard XML Document!** - **nsp** - namespaces object (prefix:URI) - **count** - number of sources merged - **error** - error information diff --git a/mergexml.js b/mergexml.js index 0ee13e8..0c1fe3f 100644 --- a/mergexml.js +++ b/mergexml.js @@ -196,7 +196,12 @@ var a = NameSpaces(doc.documentElement); for (var c in a) { if (!that.nsp[c]) { - that.dom.documentElement.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' + c, a[c]); + if (typeof that.dom.documentElement.setAttributeNS !== 'undefined') { + that.dom.documentElement.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' + c, a[c]); + } else { + // no choice but to use the incorrect setAttribute instead + that.dom.documentElement.setAttribute('xmlns:' + c, a[c]); + } that.nsp[c] = a[c]; } } @@ -234,7 +239,7 @@ if (flg) { try { for (var j = 0; j < node.attributes.length; j++) { /* add/replace attributes */ - if (node.attributes[j].namespaceURI) { + if (node.attributes[j].namespaceURI && typeof node.setAttributeNS !== 'undefined') { obj.setAttributeNS(node.attributes[j].namespaceURI, node.attributes[j].nodeName, node.attributes[j].nodeValue); } else { obj.setAttribute(node.attributes[j].nodeName, node.attributes[j].nodeValue); diff --git a/package.json b/package.json index 1b517d9..125ed5e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mergexml", - "version": "1.1.1", + "version": "1.1.2", "description": "Merge multiple XML sources", "main": "mergexml.js", "repository": { diff --git a/test/spec/merge.spec.js b/test/spec/merge.spec.js index dbd745f..621cec5 100644 --- a/test/spec/merge.spec.js +++ b/test/spec/merge.spec.js @@ -46,7 +46,7 @@ describe('Merging XML sources', function() { b = ''; merger.AddSource(a); merger.AddSource(b); - expect(merger.Get(1)).to.equal(''); + expect(merger.Get(1).trim()).to.equal(''); }); it('fails to merge second source if sources do not have a common root name', function() { @@ -58,7 +58,7 @@ describe('Merging XML sources', function() { merger.AddSource(a); merger.AddSource(b); - expect(merger.Get(1)).to.equal(''); + expect(merger.Get(1).trim()).to.equal(''); }); }); @@ -82,13 +82,13 @@ describe('Merging XML sources', function() { ''; merger.AddSource(a); merger.AddSource(b); - expect(merger.Get(1)).to.equal('s1s4s2'); + expect(merger.Get(1).trim()).to.equal('s1s4s2'); merger = new MergeXML(); merger.AddSource(a); merger.AddSource(b); - expect(merger.Get(1)).to.equal('s1s4s2'); + expect(merger.Get(1).trim()).to.equal('s1s4s2'); }); }); @@ -112,7 +112,7 @@ describe('Merging XML sources', function() { merger.AddSource(a); merger.AddSource(b); - expect(merger.Get(1)).to.equal('s1s2s4'); + expect(merger.Get(1).trim()).to.equal('s1s2s4'); }); }); @@ -135,9 +135,10 @@ describe('Merging XML sources', function() { expect(merger.error.code).to.equal(''); expect(merger.error.text).to.equal(''); - expect(merger.Get(1)).to.equal('s2'); - expect(merger.Get(0).querySelector('c').attributes[0].localName).to.equal('custom'); - expect(merger.Get(0).querySelector('c').attributes[0].namespaceURI).to.equal(ns); + expect(merger.Get(1).trim()).to.equal('s2'); + // in IE11 and below, merger.Get(0) returns an ActiveXObject we use the internal "Query" function + expect(merger.Query('//c').attributes[0].localName).to.equal('custom'); // fails in IE because + expect(merger.Query('//c').attributes[0].namespaceURI).to.equal(ns); }) })