diff --git a/src/ol/format/GMLBase.js b/src/ol/format/GMLBase.js
index de39b64953..718652acff 100644
--- a/src/ol/format/GMLBase.js
+++ b/src/ol/format/GMLBase.js
@@ -319,6 +319,15 @@ class GMLBase extends XMLFeature {
}
}
+ const len = n.attributes.length;
+ if (len > 0) {
+ value = {_content_: value};
+ for (let i = 0; i < len; i++) {
+ const attName = n.attributes[i].name;
+ value[attName] = n.attributes[i].value;
+ }
+ }
+
if (values[localName]) {
if (!(values[localName] instanceof Array)) {
values[localName] = [values[localName]];
@@ -327,15 +336,6 @@ class GMLBase extends XMLFeature {
} else {
values[localName] = value;
}
-
- const len = n.attributes.length;
- if (len > 0) {
- values[localName] = {_content_: values[localName]};
- for (let i = 0; i < len; i++) {
- const attName = n.attributes[i].name;
- values[localName][attName] = n.attributes[i].value;
- }
- }
}
if (!asFeature) {
return values;
diff --git a/test/browser/spec/ol/format/gml.test.js b/test/browser/spec/ol/format/gml.test.js
index 5aea37a7ea..3c28d0c46e 100644
--- a/test/browser/spec/ol/format/gml.test.js
+++ b/test/browser/spec/ol/format/gml.test.js
@@ -1840,6 +1840,10 @@ describe('ol.format.GML3', function () {
expect(features[0].values_['name']).to.have.length(2);
});
+ it('parses mutliple simple elements to strings', function () {
+ expect(features[0].values_['name'][0]).to.be.a('string');
+ });
+
it('creates nested property', function () {
expect(
features[0].values_['observationMethod']['CGI_TermValue']['value'][
@@ -2902,4 +2906,49 @@ describe('ol.format.GML32', function () {
expect(features[0].get('cdata')).to.be('b');
});
});
+
+ describe('when parsing multiple complex attributes', function () {
+ let features;
+ let gmlFormat;
+ before(function (done) {
+ afterLoadText('spec/ol/format/gml/gml32-complex.xml', function (xml) {
+ try {
+ gmlFormat = new GML32();
+ features = gmlFormat.readFeatures(xml);
+ } catch (e) {
+ done(e);
+ }
+ done();
+ });
+ });
+
+ it('creates 2 features', function () {
+ expect(features).to.have.length(2);
+ });
+
+ it('creates feature with three attributeA properties and two attributeB properties', function () {
+ expect(features[0].values_['attributeA']).to.have.length(3);
+ expect(features[0].values_['attributeB']).to.have.length(2);
+ });
+
+ it('parses mutliple complex elements to an array of objects', function () {
+ expect(features[0].values_['attributeA'][0]).to.be.a('object');
+ });
+
+ it('correctly structures multiple elements with attributes', function () {
+ expect(features[0].values_['attributeA'][0]['xlink:href']).to.be(
+ 'http://www.example.com/extern/1'
+ );
+ expect(features[0].values_['attributeA'][0]._content_).to.be(undefined);
+ expect(features[0].values_['attributeA'][1]['xlink:href']).to.be(
+ 'http://www.example.com/extern/2'
+ );
+ expect(features[0].values_['attributeA'][2]._content_).to.be(undefined);
+ });
+
+ it('correctly structures multiple elements with complex content', function () {
+ expect(features[0].values_['attributeB'][0].Attribute.value).to.be('foo');
+ expect(features[0].values_['attributeB'][1].Attribute.value).to.be('bar');
+ });
+ });
});
diff --git a/test/browser/spec/ol/format/gml/gml32-complex.xml b/test/browser/spec/ol/format/gml/gml32-complex.xml
new file mode 100644
index 0000000000..5ed7196a8c
--- /dev/null
+++ b/test/browser/spec/ol/format/gml/gml32-complex.xml
@@ -0,0 +1,49 @@
+
+
+
+
+ featureA
+
+
+
+
+
+ foo
+
+
+
+
+ bar
+
+
+
+
+ 0 0
+
+
+
+
+
+
+ featureB
+
+
+
+
+
+ foobar
+
+
+
+
+ barfoo
+
+
+
+
+ 1 1
+
+
+
+
+