Format.WMSGetFeatureInfo: also parse empty elements, p=me,r=erilem (closes #2867)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@11688 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -230,12 +230,14 @@ OpenLayers.Format.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Format.XML, {
|
|||||||
var child = children[i];
|
var child = children[i];
|
||||||
if (child.nodeType == 1) {
|
if (child.nodeType == 1) {
|
||||||
var grandchildren = child.childNodes;
|
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];
|
var grandchild = grandchildren[0];
|
||||||
if (grandchild.nodeType == 3 ||
|
if (grandchild.nodeType == 3 ||
|
||||||
grandchild.nodeType == 4) {
|
grandchild.nodeType == 4) {
|
||||||
var name = (child.prefix) ?
|
|
||||||
child.nodeName.split(":")[1] : child.nodeName;
|
|
||||||
var value = grandchild.nodeValue.replace(
|
var value = grandchild.nodeValue.replace(
|
||||||
this.regExes.trimSpace, "");
|
this.regExes.trimSpace, "");
|
||||||
attributes[name] = value;
|
attributes[name] = value;
|
||||||
|
|||||||
@@ -52,7 +52,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function test_read_msGMLOutput(t) {
|
function test_read_msGMLOutput(t) {
|
||||||
t.plan(12);
|
t.plan(13);
|
||||||
|
|
||||||
var parser = new OpenLayers.Format.WMSGetFeatureInfo();
|
var parser = new OpenLayers.Format.WMSGetFeatureInfo();
|
||||||
|
|
||||||
@@ -69,6 +69,28 @@
|
|||||||
t.eq(features.length, 0,
|
t.eq(features.length, 0,
|
||||||
"Parsing empty msGMLOutput response succesfull");
|
"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
|
// read 1 feature from 1 layer
|
||||||
text =
|
text =
|
||||||
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
|
'<?xml version="1.0" encoding="ISO-8859-1"?>' +
|
||||||
|
|||||||
Reference in New Issue
Block a user