I'm trying to parse a xml document to get some data for my program. I've only started learning html/js/xml two days ago so bear with me.
Here is the xml snippet i'm trying to parse:
<route tag="01" title="01 - Woodlawn">
<direction tag="01_outbound" title="To Victoria & Woodlawn">
<stop tag="stgeorge_d"/>
Here is the javascript I'm using to get down to the 'stop' node after I've loaded it using xmlDOM:
var directions = xmlDoc.getElementsByTagName("direction");
var stops = directions[directionIndex].childNodes;
for (var i=0; i<stops.length; i++) {
if(stops[i].nodeType==3) {
document.write(stops[i].getAttribute("tag"));
}
The problem is childNodes have no getAttribute method, unlike an element. I've been looking everywhere to see if there is an equilvalent method but so far my searches and trial is coming up blank.
Any help would be greatly appreciated
UPDATE: Good news. My friend helped me out and got it working. Basically what was happening was that the element 'stop' has 2 nodes: a type 3 node and a type 1 node. Instead of incrementing by 1 in my for loop (for (var i=0; i
I have tried to isolate it using if(stop[i].nodeType==1) but that didn't work.