From 6f38974fc3913bc15cb52d9bbab447c6d52d6e10 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 4 Feb 2009 18:33:13 +0000 Subject: [PATCH] Parsing emtpy attributes in GML as empty strings. Thanks for the patch bartvde. r=bartvde,me (closes #1927) git-svn-id: http://svn.openlayers.org/trunk/openlayers@8824 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Format/GML/Base.js | 3 ++- tests/Format/GML/v3.html | 33 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/OpenLayers/Format/GML/Base.js b/lib/OpenLayers/Format/GML/Base.js index ce0401a57f..dad23bb6e2 100644 --- a/lib/OpenLayers/Format/GML/Base.js +++ b/lib/OpenLayers/Format/GML/Base.js @@ -325,7 +325,8 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { } else { // Assume attribute elements have one child node and that the child // is a text node. Otherwise assume it is a geometry node. - if(node.childNodes.length == 1 && node.firstChild.nodeType == 3) { + if(node.childNodes.length == 0 || + (node.childNodes.length == 1 && node.firstChild.nodeType == 3)) { if(this.extractAttributes) { name = "_attribute"; } diff --git a/tests/Format/GML/v3.html b/tests/Format/GML/v3.html index d8f1003494..7677297b97 100644 --- a/tests/Format/GML/v3.html +++ b/tests/Format/GML/v3.html @@ -211,6 +211,39 @@ t.eq(attributes["STATE_ABBR"], "IL", "read STATE_ABBR"); t.eq(attributes["LAND_KM"], "143986.61", "read LAND_KM"); } + + function test_emptyAttribute(t) { + t.plan(4); + var str = + '' + + '' + + 'Aflu' + + '' + + '' + + '34.12 2.09' + + '' + + '' + + '84683' + + 'Algeria' + + 'place' + + 'Aflu' + + '' + + '' + + ''; + + var format = new OpenLayers.Format.GML.v3({ + featureType: "gnis_pop", + featureNS: "http://www.openplans.org/topp", + geometryName: "the_geom" + }); + + var features = format.read(str); + t.eq(features.length, 1, "read one feature"); + var attr = features[0].attributes; + t.eq(attr.name, "Aflu", "correctly read attribute value"); + t.eq(attr.foo, undefined, "bogus attribute is undefined"); + t.eq(attr.empty, "", "empty attribute value is empty string"); + } function test_write(t) { t.plan(1);