Deprecated XML.js method.

This commit is contained in:
Tim Schaub
2011-11-08 22:07:29 -07:00
parent b7c826e796
commit 5f2a6d410b
3 changed files with 53 additions and 45 deletions
+11 -11
View File
@@ -129,7 +129,7 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
var geometry = new OpenLayers.Geometry.Point(location[1], location[0]); var geometry = new OpenLayers.Geometry.Point(location[1], location[0]);
} else if (line.length > 0) { } else if (line.length > 0) {
var coords = OpenLayers.String.trim(this.concatChildValues(line[0])).split(/\s+/); var coords = OpenLayers.String.trim(this.getChildValue(line[0])).split(/\s+/);
var components = []; var components = [];
var point; var point;
for (var i=0, len=coords.length; i<len; i+=2) { for (var i=0, len=coords.length; i<len; i+=2) {
@@ -138,7 +138,7 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
} }
geometry = new OpenLayers.Geometry.LineString(components); geometry = new OpenLayers.Geometry.LineString(components);
} else if (polygon.length > 0) { } else if (polygon.length > 0) {
var coords = OpenLayers.String.trim(this.concatChildValues(polygon[0])).split(/\s+/); var coords = OpenLayers.String.trim(this.getChildValue(polygon[0])).split(/\s+/);
var components = []; var components = [];
var point; var point;
for (var i=0, len=coords.length; i<len; i+=2) { for (var i=0, len=coords.length; i<len; i+=2) {
@@ -193,17 +193,17 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
var geometry = this.createGeometryFromItem(item); var geometry = this.createGeometryFromItem(item);
/* Provide defaults for title and description */ /* Provide defaults for title and description */
var title = this.getChildValue(item, "*", "title", this.featureTitle); var title = this._getChildValue(item, "*", "title", this.featureTitle);
/* First try RSS descriptions, then Atom summaries */ /* First try RSS descriptions, then Atom summaries */
var description = this.getChildValue( var description = this._getChildValue(
item, "*", "description", item, "*", "description",
this.getChildValue(item, "*", "content", this._getChildValue(item, "*", "content",
this.getChildValue(item, "*", "summary", this.featureDescription))); this._getChildValue(item, "*", "summary", this.featureDescription)));
/* If no link URL is found in the first child node, try the /* If no link URL is found in the first child node, try the
href attribute */ href attribute */
var link = this.getChildValue(item, "*", "link"); var link = this._getChildValue(item, "*", "link");
if(!link) { if(!link) {
try { try {
link = this.getElementsByTagNameNS(item, "*", "link")[0].getAttribute("href"); link = this.getElementsByTagNameNS(item, "*", "link")[0].getAttribute("href");
@@ -212,7 +212,7 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
} }
} }
var id = this.getChildValue(item, "*", "id", null); var id = this._getChildValue(item, "*", "id", null);
var data = { var data = {
"title": title, "title": title,
@@ -225,7 +225,7 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
}, },
/** /**
* Method: getChildValue * Method: _getChildValue
* *
* Parameters: * Parameters:
* node - {DOMElement} * node - {DOMElement}
@@ -237,12 +237,12 @@ OpenLayers.Format.GeoRSS = OpenLayers.Class(OpenLayers.Format.XML, {
* {String} The value of the first child with the given tag name. Returns * {String} The value of the first child with the given tag name. Returns
* default value or empty string if none found. * default value or empty string if none found.
*/ */
getChildValue: function(node, nsuri, name, def) { _getChildValue: function(node, nsuri, name, def) {
var value; var value;
var eles = this.getElementsByTagNameNS(node, nsuri, name); var eles = this.getElementsByTagNameNS(node, nsuri, name);
if(eles && eles[0] && eles[0].firstChild if(eles && eles[0] && eles[0].firstChild
&& eles[0].firstChild.nodeValue) { && eles[0].firstChild.nodeValue) {
value = OpenLayers.Format.XML.prototype.getChildValue(eles[0]); value = this.getChildValue(eles[0]);
} else { } else {
value = (def == undefined) ? "" : def; value = (def == undefined) ? "" : def;
} }
-34
View File
@@ -379,40 +379,6 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, {
return value; return value;
}, },
/**
* APIMethod: concatChildValues
* *Deprecated*. Use <getChildValue> instead.
*
* Concatenate the value of all child nodes if any exist, or return an
* optional default string. Returns an empty string if no children
* exist and no default value is supplied. Not optimized for large
* numbers of child nodes.
*
* Parameters:
* node - {DOMElement} The element used to look for child values.
* def - {String} Optional string to return in the event that no
* child exist.
*
* Returns:
* {String} The concatenated value of all child nodes of the given node.
*/
concatChildValues: function(node, def) {
var value = "";
var child = node.firstChild;
var childValue;
while(child) {
childValue = child.nodeValue;
if(childValue) {
value += childValue;
}
child = child.nextSibling;
}
if(value == "" && def != undefined) {
value = def;
}
return value;
},
/** /**
* APIMethod: isSimpleContent * APIMethod: isSimpleContent
* Test if the given node has only simple content (i.e. no child element * Test if the given node has only simple content (i.e. no child element
+42
View File
@@ -1702,3 +1702,45 @@ OpenLayers.Control.MouseToolbar = OpenLayers.Class(
OpenLayers.Control.MouseToolbar.X = 6; OpenLayers.Control.MouseToolbar.X = 6;
OpenLayers.Control.MouseToolbar.Y = 300; OpenLayers.Control.MouseToolbar.Y = 300;
/**
* Class: OpenLayers.Format.XML
*/
OpenLayers.Util.extend(OpenLayers.Format.XML.prototype, {
/**
* APIMethod: concatChildValues
* *Deprecated*. Use <getChildValue> instead.
*
* Concatenate the value of all child nodes if any exist, or return an
* optional default string. Returns an empty string if no children
* exist and no default value is supplied. Not optimized for large
* numbers of child nodes.
*
* Parameters:
* node - {DOMElement} The element used to look for child values.
* def - {String} Optional string to return in the event that no
* child exist.
*
* Returns:
* {String} The concatenated value of all child nodes of the given node.
*/
concatChildValues: function(node, def) {
var value = "";
var child = node.firstChild;
var childValue;
while(child) {
childValue = child.nodeValue;
if(childValue) {
value += childValue;
}
child = child.nextSibling;
}
if(value == "" && def != undefined) {
value = def;
}
return value;
}
});