diff --git a/lib/OpenLayers/Format/GML.js b/lib/OpenLayers/Format/GML.js index 033536120e..36d8f5352c 100644 --- a/lib/OpenLayers/Format/GML.js +++ b/lib/OpenLayers/Format/GML.js @@ -295,7 +295,7 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, { // look for nodeList = this.getElementsByTagNameNS(node, this.gmlns, "posList"); if(nodeList.length > 0) { - coordString = nodeList[0].firstChild.nodeValue; + coordString = this.concatChildValues(nodeList[0]); coordString = coordString.replace(this.regExes.trimSpace, ""); coords = coordString.split(this.regExes.splitSpace); var dim = parseInt(nodeList[0].getAttribute("dimension")); @@ -314,7 +314,7 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, { nodeList = this.getElementsByTagNameNS(node, this.gmlns, "coordinates"); if(nodeList.length > 0) { - coordString = nodeList[0].firstChild.nodeValue; + coordString = this.concatChildValues(nodeList[0]); coordString = coordString.replace(this.regExes.trimSpace, ""); coordString = coordString.replace(this.regExes.trimComma, diff --git a/lib/OpenLayers/Format/XML.js b/lib/OpenLayers/Format/XML.js index 44920e06a8..15afffa1a5 100644 --- a/lib/OpenLayers/Format/XML.js +++ b/lib/OpenLayers/Format/XML.js @@ -256,6 +256,62 @@ OpenLayers.Format.XML = OpenLayers.Class(OpenLayers.Format, { } return attributeValue; }, + + /** + * APIMethod: getChildValue + * Get the value of the first child node if it exists, or return an + * optional default string. Returns an empty string if no first child + * exists and no default value is supplied. + * + * Parameters: + * node - {DOMElement} The element used to look for a first child value. + * def - {String} Optional string to return in the event that no + * first child value exists. + * + * Returns: + * {String} The value of the first child of the given node. + */ + getChildValue: function(node, def) { + var value; + try { + value = node.firstChild.nodeValue; + } catch(e) { + value = (def != undefined) ? def : ""; + } + return value; + }, + + /** + * APIMethod: concatChildValues + * 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: hasAttributeNS