Correct parsing multi-properties with attributes

When parsing GML then conversion of properties containing XML attributes
to objects with a _content_ property must occur before the handling of
multiple attributes (conversion/adding to an array), as otherwise the
_content_ property and attributes are set on the array and not on the
array element.

Prior to this change, only multiple properties without attributes could
be correctly parsed.

Example problemeatic GML section:
<Link xlink:href="http://example.com/a"/>
<Link xlink:href="http://example.com/b"/>

Resulting property as JSON extract after this change:
{
  "Link": [
    {
      "_content_": undefined,
      "xlink:href": "http://example.com/a",
    },
    {
      "_content_": undefined,
      "xlink:href": "http://example.com/b"
    }
  ]
}

Prior to this change, the _content_ property and the properties for the
XML attributes would be set on the resulting JS Array object, with
previous entries being represented as nested arrays.
This commit is contained in:
Edward Nash
2021-10-29 15:42:50 +02:00
parent aff751bdf0
commit e1b4634fa4

View File

@@ -304,6 +304,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]];
@@ -312,15 +321,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;