I am trying to transform a JSON object to XML, but i have somehow get stuck in jscript (not an expert). Here is the code:
...
var GEOJSON_PARSER = new OpenLayers.Format.GeoJSON();
var vectorLayerAsJson = GEOJSON_PARSER.write(vlayer.features);
...
var x2js = new X2JS();
...
var xmlDocStr2 = x2js.json2xml_str(vectorLayerAsJson);
alert(xmlDocStr2);
...
// JSON arrays to string
var xmlDoc1 = x2js.json2xml_str({
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[22580, -24812],
[24772, -28076],
[27732, -24204],
[22580, -24812]
]
]
}
}]
});
alert(xmlDoc1);
In the first case the json2xml_str(vectorLayerAsJson) function returns something like a JSON object however in the second it returns the correct XML.
Both objects are identical "vectorLayerAsJson" is the one declared as "type":"FeatureCollection ..."
in the second case.
I have also tried alternate ways of calling x2js.json2xml_str
such as x2js.json2xml_str($.parseJSON($("vectorLayerAsJson").val()));
with no success!
Any ideas?