fixed KML parsing for cases where a line break is only before or after a CDATA block. r=bartvde (closes #2398)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@10138 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
ahocevar
2010-03-21 21:10:33 +00:00
parent 1f77d278ef
commit f4fbc96036
2 changed files with 8 additions and 2 deletions

View File

@@ -885,12 +885,18 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
child = children[i];
if(child.nodeType == 1) {
grandchildren = child.childNodes;
if(grandchildren.length == 1 || grandchildren.length == 3) {
if(grandchildren.length >= 1 || grandchildren.length <= 3) {
var grandchild;
switch (grandchildren.length) {
case 1:
grandchild = grandchildren[0];
break;
case 2:
var c1 = grandchildren[0];
var c2 = grandchildren[1];
grandchild = c1.nodeType == 3 || c1.nodeType == 4 ?
c1 : c2;
break;
case 3:
default:
grandchild = grandchildren[1];

View File

@@ -37,7 +37,7 @@
function test_Format_KML_readCdataAttributes_20(t) {
t.plan(2);
var cdata = '<kml xmlns="http://earth.google.com/kml/2.0"><Document><Placemark><name><![CDATA[Pezinok]]></name><description><![CDATA[Full of text.]]></description><styleUrl>#rel1.0</styleUrl><Point> <coordinates>17.266666, 48.283333</coordinates></Point></Placemark></Document></kml>';
var cdata = '<kml xmlns="http://earth.google.com/kml/2.0"><Document><Placemark><name><![CDATA[Pezinok]]> </name><description><![CDATA[Full of text.]]></description><styleUrl>#rel1.0</styleUrl><Point> <coordinates>17.266666, 48.283333</coordinates></Point></Placemark></Document></kml>';
var features = (new OpenLayers.Format.KML()).read(cdata);
t.eq(features[0].attributes.description, "Full of text.", "Description attribute in cdata read correctly");
t.eq(features[0].attributes.name, "Pezinok", "title attribute in cdata read correctly");