From db153e199af38c3168d6f1f97f9e45f17f41115d Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Fri, 5 Feb 2010 20:17:59 +0000 Subject: [PATCH] Correctly parse feature attributes when the attribute name matches the feature type name. r=bartvde (closes #2435) git-svn-id: http://svn.openlayers.org/trunk/openlayers@10027 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Format/GML/Base.js | 15 +++++--- tests/Format/GML/v3.html | 62 +++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/lib/OpenLayers/Format/GML/Base.js b/lib/OpenLayers/Format/GML/Base.js index e22aa047a3..92e874f93a 100644 --- a/lib/OpenLayers/Format/GML/Base.js +++ b/lib/OpenLayers/Format/GML/Base.js @@ -331,12 +331,17 @@ OpenLayers.Format.GML.Base = OpenLayers.Class(OpenLayers.Format.XML, { // geometry or attributes. var name; var local = node.localName || node.nodeName.split(":").pop(); - if (!this.singleFeatureType && - (OpenLayers.Util.indexOf(this.featureType, local) != -1)) { + // Since an attribute can have the same name as the feature type + // we only want to read the node as a feature if the parent + // node can have feature nodes as children. In this case, the + // obj.features property is set. + if (obj.features) { + if (!this.singleFeatureType && + (OpenLayers.Util.indexOf(this.featureType, local) !== -1)) { name = "_typeName"; - } - else if(local == this.featureType) { - name = "_typeName"; + } else if(local === this.featureType) { + name = "_typeName"; + } } else { // Assume attribute elements have one child node and that the child // is a text node. Otherwise assume it is a geometry node. diff --git a/tests/Format/GML/v3.html b/tests/Format/GML/v3.html index 0a53c9a1a3..4d452fc781 100644 --- a/tests/Format/GML/v3.html +++ b/tests/Format/GML/v3.html @@ -244,6 +244,24 @@ t.eq(attr.foo, undefined, "bogus attribute is undefined"); t.eq(attr.empty, "", "empty attribute value is empty string"); } + + function test_repeatedName(t) { + // test that if an attribute name matches the featureType, all goes well + t.plan(2); + var doc = readXML("v3/repeated-name.xml"); + var format = new OpenLayers.Format.GML.v3({ + featureType: "zoning", + featureNS: "http://opengeo.org/#medford", + geometryName: "the_geom", + xy: false + }); + var features = format.read(doc.documentElement); + + t.eq(features.length, 1, "read one feature"); + var atts = features[0].attributes; + t.eq(atts.zoning, "I-L", "correct zoning attribute on zoning feature type"); + + } function test_write(t) { t.plan(1); @@ -724,5 +742,49 @@ --> +