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);