#894 - bind this to xmldom closure
git-svn-id: http://svn.openlayers.org/trunk/openlayers@3875 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -62,7 +62,7 @@ OpenLayers.Format.XML.prototype =
|
|||||||
text = text.substring(index);
|
text = text.substring(index);
|
||||||
}
|
}
|
||||||
var node = OpenLayers.Util.Try(
|
var node = OpenLayers.Util.Try(
|
||||||
function() {
|
(function() {
|
||||||
var xmldom;
|
var xmldom;
|
||||||
/**
|
/**
|
||||||
* Since we want to be able to call this method on the prototype
|
* Since we want to be able to call this method on the prototype
|
||||||
@@ -72,10 +72,11 @@ OpenLayers.Format.XML.prototype =
|
|||||||
xmldom = new ActiveXObject("Microsoft.XMLDOM");
|
xmldom = new ActiveXObject("Microsoft.XMLDOM");
|
||||||
} else {
|
} else {
|
||||||
xmldom = this.xmldom;
|
xmldom = this.xmldom;
|
||||||
|
|
||||||
}
|
}
|
||||||
xmldom.loadXML(text);
|
xmldom.loadXML(text);
|
||||||
return xmldom;
|
return xmldom;
|
||||||
},
|
}).bind(this),
|
||||||
function() {
|
function() {
|
||||||
return new DOMParser().parseFromString(text, 'text/xml');
|
return new DOMParser().parseFromString(text, 'text/xml');
|
||||||
},
|
},
|
||||||
@@ -180,6 +181,7 @@ OpenLayers.Format.XML.prototype =
|
|||||||
if(node.getElementsByTagNameNS) {
|
if(node.getElementsByTagNameNS) {
|
||||||
elements = node.getElementsByTagNameNS(uri, name);
|
elements = node.getElementsByTagNameNS(uri, name);
|
||||||
} else {
|
} else {
|
||||||
|
// brute force method
|
||||||
var allNodes = node.getElementsByTagName("*");
|
var allNodes = node.getElementsByTagName("*");
|
||||||
var potentialNode, fullName;
|
var potentialNode, fullName;
|
||||||
for(var i=0; i<allNodes.length; ++i) {
|
for(var i=0; i<allNodes.length; ++i) {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
'<' + '/ol:root>';
|
'<' + '/ol:root>';
|
||||||
|
|
||||||
function test_Format_XML_constructor(t) {
|
function test_Format_XML_constructor(t) {
|
||||||
t.plan(4);
|
t.plan(window.ActiveXObject ? 5 : 4);
|
||||||
|
|
||||||
var options = {'foo': 'bar'};
|
var options = {'foo': 'bar'};
|
||||||
var format = new OpenLayers.Format.XML(options);
|
var format = new OpenLayers.Format.XML(options);
|
||||||
@@ -26,13 +26,18 @@
|
|||||||
"new OpenLayers.Format.XML returns object" );
|
"new OpenLayers.Format.XML returns object" );
|
||||||
t.eq(format.foo, "bar", "constructor sets options correctly");
|
t.eq(format.foo, "bar", "constructor sets options correctly");
|
||||||
t.eq(typeof format.read, "function", "format has a read function");
|
t.eq(typeof format.read, "function", "format has a read function");
|
||||||
t.eq(typeof format.write, "function", "format has a write function");
|
t.eq(typeof format.write, "function", "format has a write function");
|
||||||
|
|
||||||
|
if(format.xmldom) {
|
||||||
|
t.ok(true, "format only has xmldom in browsers with ActiveX");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Format_XML_read(t) {
|
function test_Format_XML_read(t) {
|
||||||
t.plan(5);
|
|
||||||
|
|
||||||
var format = new OpenLayers.Format.XML();
|
var format = new OpenLayers.Format.XML();
|
||||||
|
t.plan(format.xmldom ? 11 : 10);
|
||||||
|
|
||||||
var doc = format.read(text);
|
var doc = format.read(text);
|
||||||
t.eq(doc.nodeType, 9,
|
t.eq(doc.nodeType, 9,
|
||||||
"doc has the correct node type");
|
"doc has the correct node type");
|
||||||
@@ -44,6 +49,26 @@
|
|||||||
"doc root has the correct node name");
|
"doc root has the correct node name");
|
||||||
t.eq(doc.documentElement.childNodes[1].firstChild.nodeValue, "junk2",
|
t.eq(doc.documentElement.childNodes[1].firstChild.nodeValue, "junk2",
|
||||||
"second child of doc root has correct child node");
|
"second child of doc root has correct child node");
|
||||||
|
|
||||||
|
// read can also be called on the prototype directly
|
||||||
|
doc = OpenLayers.Format.XML.prototype.read(text);
|
||||||
|
t.eq(doc.nodeType, 9,
|
||||||
|
"doc has the correct node type");
|
||||||
|
t.eq(doc.nodeName, "#document",
|
||||||
|
"doc has the correct node name");
|
||||||
|
t.ok(doc.documentElement,
|
||||||
|
"ok to access doc.documentElement");
|
||||||
|
t.eq(doc.documentElement.nodeName, "ol:root",
|
||||||
|
"doc root has the correct node name");
|
||||||
|
t.eq(doc.documentElement.childNodes[1].firstChild.nodeValue, "junk2",
|
||||||
|
"second child of doc root has correct child node");
|
||||||
|
|
||||||
|
// where appropriate, make sure doc is loaded into xmldom property
|
||||||
|
if(format.xmldom) {
|
||||||
|
t.eq(format.xmldom.documentElement.childNodes[1].firstChild.nodeValue,
|
||||||
|
"junk2",
|
||||||
|
"second child of doc root has correct child node");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function test_Format_XML_write(t) {
|
function test_Format_XML_write(t) {
|
||||||
|
|||||||
Reference in New Issue
Block a user