PDA

View Full Version : Use xml file data to get external data and add to xml file


ruraldev
10-25-2009, 12:19 PM
Hi

I have been trying to find out how to get data from an xml file on another page and merge it as a attribute on the original xml file and save/overwrite the original file with the new data added.

I hope that kind of explains it!

The following code parses data from http://80.176.208.244/cycle/downloads/1/route.gpx


// Read the data from route.gpx

var request = GXmlHttp.create();
request.open("GET", "route.gpx", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = GXml.parse(request.responseText);
// obtain the array of markers and loop through it
var markers = xmlDoc.documentElement.getElementsByTagName("trkpt");

for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers[i].getAttribute("lat"));
var lng = parseFloat(markers[i].getAttribute("lon"));


then I send it to http://80.176.208.244/cycle/downloads/1/altitude.php which returns a value in xml format

using this code


GDownloadUrl('altitude.php?lat=' +point.lat()+ '&lng=' +point.lng(), function(data) {
var doc = GXml.parse(data);
altitudes[i] = parseInt(GXml.value(doc));
nodes = nodes+1;
if (nodes == maxNodes) {
drawProfile();


The goal is to create a new xml file with elements with the following attributes (lat=,lon=,altitude=)

If it helps to see the code in use http://80.176.208.244/cycle/downloads/1/gmap.php

It seems very complicated to me but perhaps it's easier than I think.

Hope someone can help point me in the right direction.

Thanks

Gordon