inserting an xml prolog into a gpx file when generating it with SimpleStorage can be achieved in a few steps.
- Begin the gpx file with the xml prolog
Start the gpx file with the xml prolog that you want to include. The xml prolog is the first line of the file, and it declares the version of the xml language being used. The standard xml prolog looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
- Use the set method
After setting up the xml prolog, use the set method to contain the latitudes, longitudes, and time stamps. This will look something like this:
SimpleStorage.set('gpx', {
waypoints: [
{ latitude:37.779182013755096, longitude:-122.40162551486271, time:'2017-09-15T08:00:00Z' },
{ latitude:37.778851035476524, longitude:-122.40207734107971, time:'2017-09-15T08:01:00Z' }
],
creator: 'SimpleStorage'
});
- Create the gpx file
From the information that you saved with SimpleStorage, you can now create the gpx file. Use the following code to generate a file with the xml prolog plus the waypoints and creator information:
let waypoints = SimpleStorage.get('gpx').waypoints;
let gpx = '<?xml version="1.0" encoding="UTF-8" ?><gpx creator="SimpleStorage" version="1.1">';
for (let waypoint of waypoints) {
gpx += '<wpt lat="' + waypoint.latitude + '" lon="' + waypoint.longitude + '">';
gpx += '<time>' + waypoint.time + '</time>';
gpx += '</wpt>';
}
gpx += '</gpx>';
That's all you have to do to create a gpx file with an xml prolog using SimpleStorage.