From e1b1c814de494ef0b17c5e1342420f7132309866 Mon Sep 17 00:00:00 2001 From: ahocevar Date: Fri, 3 Apr 2009 16:52:26 +0000 Subject: [PATCH] create attributes with null value for empty attribute nodes. Original patch by milovanderlinden, simplified by tschaub. r=me (closes #1556) git-svn-id: http://svn.openlayers.org/trunk/openlayers@9179 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Format/GML.js | 6 ++++++ tests/Format/GML.html | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Format/GML.js b/lib/OpenLayers/Format/GML.js index de7b16dd9a..d6ba5d409a 100644 --- a/lib/OpenLayers/Format/GML.js +++ b/lib/OpenLayers/Format/GML.js @@ -558,6 +558,12 @@ OpenLayers.Format.GML = OpenLayers.Class(OpenLayers.Format.XML, { this.regExes.trimSpace, ""); attributes[name] = value; } + } else { + // If child has no childNodes (grandchildren), + // set an attribute with null value. + // e.g. becomes + // {fieldname: null} + attributes[child.nodeName.split(":").pop()] = null; } } } diff --git a/tests/Format/GML.html b/tests/Format/GML.html index 3548a5b0ee..1352eb2541 100644 --- a/tests/Format/GML.html +++ b/tests/Format/GML.html @@ -153,11 +153,12 @@ t.eq(data[0].geometry.components.length, 2, "rings length correct"); } function test_Format_GML_read_attributes(t) { - t.plan(2); + t.plan(3); var parser = new OpenLayers.Format.GML(); data = parser.read(test_content[0]); t.eq(data[0].attributes['NAME'], "WY", "Simple Attribute data is read correctly."); t.eq(data[0].attributes['LONGNAME'], "Wyoming", "Attribute data is read from CDATA node correctly."); + t.ok(data[0].attributes['EMPTYATTR'] === null, "Attribute set to null for empty element."); } function test_Format_GML_read_envelope_geom(t) { t.plan(13); @@ -338,7 +339,7 @@ t.xml_eq(output, expect, "[xy true] Bounds correctly written as gml:Box"); } - var test_content = ['\n\n \n \n -1254041.389711702250906.9515983529\n -634517.1199908922762236.2940800377\n \n \n \n \n -634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0\n WY\n \n \n \n\n', + var test_content = ['\n\n \n \n -1254041.389711702250906.9515983529\n -634517.1199908922762236.2940800377\n \n \n \n \n -634517.11999089224,691849.77929356066,0 -653761.64509297756,471181.53429472551,0 -673343.60852865304,250906.9515983529,0 -1088825.734430399,299284.85108220269,0 -1254041.3897117018,324729.27754874947,0 -1235750.4212498858,434167.33911316615,0 -1190777.7803201093,704392.96327195223,0 -1181607.835811228,762236.29408003774,0 -634517.11999089224,691849.77929356066,0\n WY\n \n \n \n\n', '