openlayers/openlayers — Issue #100: Feature attributes are not serialized to KML format
Author: towa48
Created: 2011-12-10 10:29:09+00:00
State: open

Feature attributes are not serialized to KML format. Method OpenLayers.Format.KML.createPlacemarkXML() serialize only name, description and geometry. But i have portion of ExtendedData in my features. Method OpenLayers.Format.KML.parseExtendedData() deserialize Data and SimpleData elemnts to objects and do not make a difference between them.

http://code.google.com/apis/kml/documentation/kmlreference.html#extendeddata
How can I choose between Data and SimpleData?
This code serialize to Data by default.

```js
OpenLayers.Format.KML.prototype.createPlacemarkXML = function (feature) {
var placemarkNode = this.createElementNS(this.kmlns, "Placemark"),
placemarkName = this.createElementNS(this.kmlns, "name"),
placemarkDesc = this.createElementNS(this.kmlns, "description"),
name, desc, extendedData, attributeName, geometryNode;

// Placemark id
if (feature.fid != null) {
placemarkNode.setAttribute("id", feature.fid);
}

// Placemark name
name = feature.style && feature.style.label ? feature.style.label : feature.attributes.name || feature.id;
placemarkName.appendChild(this.createTextNode(name));
placemarkNode.appendChild(placemarkName);

// Placemark description
desc = feature.attributes.description || this.placemarksDesc;
placemarkDesc.appendChild(this.createTextNode(desc));
placemarkNode.appendChild(placemarkDesc);

// Geometry node (Point, LineString, etc. nodes)
geometryNode = this.buildGeometryNode(feature.geometry);
placemarkNode.appendChild(geometryNode);

// Search for extended data (see KML spec).
for (attributeName in feature.attributes) {
if (feature.attributes[attributeName].value) {
if (!extendedData) {
extendedData = this.createElementNS(this.kmlns, "ExtendedData");
}

// value element is necessary
var data = this.createElementNS(this.kmlns, "Data"),
value = this.createElementNS(this.kmlns, "value");
data.setAttribute("name", attributeName);
value.appendChild(this.createTextNode(feature.attributes[attributeName].value));
data.appendChild(value);
extendedData.appendChild(data);

// displayName element
if (feature.attributes[attributeName].displayName) {
var displayName = this.createElementNS(this.kmlns, "displayName");
displayName.appendChild(this.createTextNode(feature.attributes[attributeName].displayName));
data.appendChild(displayName);
extendedData.appendChild(displayName);
}
}
}
if (extendedData) {
placemarkNode.appendChild(extendedData);
}

// TODO: implement serialization for other placemark elements.
// See KML spec http://code.google.com/apis/kml/documentation/kmlreference.html#placemark
return placemarkNode;
}
```