[OpenLayers-Commits] r11688 - in trunk/openlayers: lib/OpenLayers/Format tests/Format

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Mar 10 11:36:31 EST 2011


Author: bartvde
Date: 2011-03-10 08:36:30 -0800 (Thu, 10 Mar 2011)
New Revision: 11688

Modified:
   trunk/openlayers/lib/OpenLayers/Format/WMSGetFeatureInfo.js
   trunk/openlayers/tests/Format/WMSGetFeatureInfo.html
Log:
Format.WMSGetFeatureInfo: also parse empty elements, p=me,r=erilem (closes #2867)

Modified: trunk/openlayers/lib/OpenLayers/Format/WMSGetFeatureInfo.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/WMSGetFeatureInfo.js	2011-03-09 23:18:43 UTC (rev 11687)
+++ trunk/openlayers/lib/OpenLayers/Format/WMSGetFeatureInfo.js	2011-03-10 16:36:30 UTC (rev 11688)
@@ -230,12 +230,14 @@
                 var child = children[i];
                 if (child.nodeType == 1) {
                     var grandchildren = child.childNodes;
-                    if (grandchildren.length == 1) {
+                    var name = (child.prefix) ?
+                        child.nodeName.split(":")[1] : child.nodeName;
+                    if (grandchildren.length == 0) {
+                        attributes[name] = null
+                    } else if (grandchildren.length == 1) {
                         var grandchild = grandchildren[0];
                         if (grandchild.nodeType == 3 ||
                             grandchild.nodeType == 4) {
-                            var name = (child.prefix) ? 
-                                child.nodeName.split(":")[1] : child.nodeName;
                             var value = grandchild.nodeValue.replace(
                                 this.regExes.trimSpace, "");
                             attributes[name] = value;

Modified: trunk/openlayers/tests/Format/WMSGetFeatureInfo.html
===================================================================
--- trunk/openlayers/tests/Format/WMSGetFeatureInfo.html	2011-03-09 23:18:43 UTC (rev 11687)
+++ trunk/openlayers/tests/Format/WMSGetFeatureInfo.html	2011-03-10 16:36:30 UTC (rev 11688)
@@ -52,7 +52,7 @@
     }
 
     function test_read_msGMLOutput(t) {
-        t.plan(12);
+        t.plan(13);
         
         var parser = new OpenLayers.Format.WMSGetFeatureInfo();
 
@@ -69,6 +69,28 @@
         t.eq(features.length, 0,
              "Parsing empty msGMLOutput response succesfull");
 
+        // read empty attribute
+        text =
+            '<?xml version="1.0" encoding="ISO-8859-1"?>' +
+            '<msGMLOutput ' +
+            '    xmlns:gml="http://www.opengis.net/gml"' +
+            '    xmlns:xlink="http://www.w3.org/1999/xlink"' +
+            '    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">' +
+            '   <AAA64_layer>' +
+            '           <AAA64_feature>' +
+            '                   <gml:boundedBy>' +
+            '                           <gml:Box srsName="EPSG:28992">' +
+            '                                   <gml:coordinates>107397.266000,460681.063000 116568.188000,480609.250000</gml:coordinates>' +
+            '                           </gml:Box>' +
+            '                   </gml:boundedBy>' +
+            '                   <FOO>bar</FOO>' +
+            '                   <EMPTY></EMPTY>' +
+            '           </AAA64_feature>' +
+            '   </AAA64_layer>' +
+            '</msGMLOutput>';
+        features = parser.read(text);
+        t.eq((features[0].attributes.EMPTY === null), true, "Empty attribute is parsed as null");
+
         // read 1 feature from 1 layer
         text = 
             '<?xml version="1.0" encoding="ISO-8859-1"?>' +



More information about the Commits mailing list