OpenLayers OpenLayers

Changeset 4410

Show
Ignore:
Timestamp:
09/20/07 13:06:04 (1 year ago)
Author:
tschaub
Message:

Adding a concatChildValues method to the XML parser. This gets around a messy 4kb limit for text node lengths - over which browsers split values among multiple siblings (see #1006).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Format/GML.js

    r4352 r4410  
    296296            nodeList = this.getElementsByTagNameNS(node, this.gmlns, "posList"); 
    297297            if(nodeList.length > 0) { 
    298                 coordString = nodeList[0].firstChild.nodeValue
     298                coordString = this.concatChildValues(nodeList[0])
    299299                coordString = coordString.replace(this.regExes.trimSpace, ""); 
    300300                coords = coordString.split(this.regExes.splitSpace); 
     
    315315                                                       "coordinates"); 
    316316                if(nodeList.length > 0) { 
    317                     coordString = nodeList[0].firstChild.nodeValue
     317                    coordString = this.concatChildValues(nodeList[0])
    318318                    coordString = coordString.replace(this.regExes.trimSpace, 
    319319                                                      ""); 
  • trunk/openlayers/lib/OpenLayers/Format/XML.js

    r4302 r4410  
    257257        return attributeValue; 
    258258    }, 
     259     
     260    /** 
     261     * APIMethod: getChildValue 
     262     * Get the value of the first child node if it exists, or return an 
     263     *     optional default string.  Returns an empty string if no first child 
     264     *     exists and no default value is supplied. 
     265     * 
     266     * Parameters: 
     267     * node - {DOMElement} The element used to look for a first child value. 
     268     * def - {String} Optional string to return in the event that no 
     269     *     first child value exists. 
     270     * 
     271     * Returns: 
     272     * {String} The value of the first child of the given node. 
     273     */ 
     274    getChildValue: function(node, def) { 
     275        var value; 
     276        try { 
     277            value = node.firstChild.nodeValue; 
     278        } catch(e) { 
     279            value = (def != undefined) ? def : ""; 
     280        } 
     281        return value; 
     282    }, 
     283 
     284    /** 
     285     * APIMethod: concatChildValues 
     286     * Concatenate the value of all child nodes if any exist, or return an 
     287     *     optional default string.  Returns an empty string if no children 
     288     *     exist and no default value is supplied.  Not optimized for large 
     289     *     numbers of child nodes. 
     290     * 
     291     * Parameters: 
     292     * node - {DOMElement} The element used to look for child values. 
     293     * def - {String} Optional string to return in the event that no 
     294     *     child exist. 
     295     * 
     296     * Returns: 
     297     * {String} The concatenated value of all child nodes of the given node. 
     298     */ 
     299    concatChildValues: function(node, def) { 
     300        var value = ""; 
     301        var child = node.firstChild; 
     302        var childValue; 
     303        while(child) { 
     304            childValue = child.nodeValue; 
     305            if(childValue) { 
     306                value += childValue; 
     307            } 
     308            child = child.nextSibling; 
     309        } 
     310        if(value == "" && def != undefined) { 
     311            value = def; 
     312        } 
     313        return value; 
     314    }, 
    259315 
    260316    /**