was hoping for some help with an xml file that my program generates and is downloaded to clients computer.
I'm generating a fight plan in an xml format that is then loaded into a flight simulator - which is not working. It appears to be an encoding issue with a coordinate in the xml file:
This coordinate and encoding works(from another program) (copy and paste in Bing maps to test):
S23° 5' 59.80",E149° 34' 46.14"
S23%B0%205%27%2059.80%22%2CE149%B0%2034%27%2046.14%22
This same coordinate and but different encoding (my xml output) doesn't work(copy and paste in Bing maps to test):
S25° 5′ 29.80",E149° 34′ 46.14"
S25%B0%A05%u2032%A029.80%22%2CE149%B0%A034%u2032%A046.14%22
My Javascript function where the XML file is created and downloaded:
function saveFlightPlan(document, flightPath_data) {
filename = 'flight_plan.pln';
var dep_dest_array = [];
//build flight plan data to send to server so it can determine departure and arrival airports
for (var i = 0; i < flightPath_data.length; i++) {
airport_name = flightPath_data[i]['waypoint'];
latlng_array = flightPath_data[i]['latLng'];
lat = latlng_array[0];
lng = latlng_array[1];
coordinate = {'airport_name': airport_name, 'lat': lat, 'lon': lng};
dep_dest_array.push(coordinate);
}
jsonified_data = JSON.stringify(dep_dest_array);
fetch('http://localhost:5000/build_flightplan', {
method: "POST",
credentials: "include",
body: jsonified_data,
cache: "no-cache",
headers: new Headers({
"content-type": "application/json"
})
})
.then(response => response.json())
.then(dep_dest_data => {
console.log(JSON.stringify(dep_dest_data));
console.log(dep_dest_data['dep_airport']);
console.log(dep_dest_data['dest_airport']);
//build flight plan now that we have departure and arrival airports
content = buildFlightPlan(flightPath_data, dep_dest_data);
const a = document.createElement('a');
const file = new Blob([content], {type: 'text/xml'});
a.href= URL.createObjectURL(file);
a.download = filename;
a.click();
URL.revokeObjectURL(a.href);
var flight_plan_modal = document.getElementById("Flight_plan_modal");
flight_plan_modal.classList.remove('show');
// flight_plan_modal.setAttribute('aria-hidden', 'true');
// flight_plan_modal.setAttribute('style', 'display: none');
})
}
So, Im' at a loss on how to encode my XML file so it produces the first type of encoding (S23%B0%205%27%2059.80%22%2CE149%B0%2034%27%2046.14%22)??
Javscript where i create the xml document:
// Create the XML document
var parser = new DOMParser();
var xmlDoc = parser.parseFromString('<?xml version="1.0" encoding="utf-8"?><SimBase.Document></SimBase.Document>', "application/xml");
...
...
xmlDoc_string = new XMLSerializer().serializeToString(xmlDoc)
xml_formatted = formatXml(xmlDoc_string);
return xml_formatted;
Any help appreciated :)
UPDATE:
Actually, I think its got to do with this bit of code that converts the lat-long:
a, // decimal value (ex. -14.23463)
b, // boundary; accepts "90" (Latitude) or "180" (Longitude)
c // precision for seconds
){
var
// get the direction indicator
H='NSEW'[
2*(b!=90) // expressions in brackets are booleans, that get coerced into 0 or 1
+(a<0) // is the decimal value less than 0, coerced into 0 or 1
],
a=(a<0?-a:a)%b, // convert value to absolute. shorten than Math.abs(a)
// also get the modulo of the value and the boundary
D=0|a, // Degress: get the integer value; like Math.floor(a)
a=(a-D)*60, // calulate the rest and multiply by 60
M=0|a, // Minutes
a=(a-M)*60,
S=a.toFixed(c); // Seconds
// return formatted values joined by non-breaking space
return [H+D+'°',M+'′',S+'"'].join('\xA0')
}```
I changed the return line and now its working. Thanks for your help :)
```return [H+D+'°',M+'\'',S+'"'].join(' ')```