XML input to HTML via JS

C

clsnyder

Hi -
I am trying to input data from an xml file into some javasript code for
an html document, but am not familiar enough with how to traverse the
nodes... Here is what doesn't work:

function myclick(i) {
gmarkers.openInfoWindowHtml(htmls);
}

// Read the data from example.xml
var request = GXmlHttp.create();
request.open("GET", "Ann_Surg_Results.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = request.responseXML;
// obtain the array of markers and loop through it
var markers =
xmlDoc.documentElement.getElementsByTagName("marker");

for (var i = 0; i < markers.length; i++) {
// obtain the attribues of each marker
var lat = parseFloat(markers.childNodes[2].text);
var lng = parseFloat(markers.childNodes[3].text);
var point = new GPoint(lng,lat);
var zip = markers.childNodes[0].text;
var numpubs = markers.childNodes[1].text;
var city = markers.childNodes[4].text;
// create the marker
var marker = createMarker(point, numpubs, zip, city);
map.addOverlay(marker);
document.getElementById("message").innerHTML += numpubs + '&nbsp;'
+ '&nbsp;' + city + '<br>';
}
}
}
request.send(null);
} else {
alert("Sorry, the Google Maps API is not compatible with this
browser");
}
}

Here is what the XML structure is :
<markers>
<marker>
<zip>40536</zip>
<Frequency>1</Frequency>
<lat>38.032075</lat>
<long>-084.508361</long>
<CITY>LEXINGTON</CITY>
<STATE>KY</STATE>
</marker>
<marker>
<zip>48109</zip>
<Frequency>1</Frequency>
<lat>42.276324</lat>
<long>-083.711228</long>
<CITY>ANN ARBOR</CITY>
<STATE>MI</STATE>
</marker>......


Any help is appreciated

CLS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top