thanks in advance for all your help!
i'm fairly new to javascript, but i have a fairly strong background in java, so i thought i would try it out on this project i'm working on.
essentially, what i'm trying to do is read data from an xml file and create the html code for the page i'm making. i used the script from w3schools found here. I've altered it and gotten it to pull the data from my own xml and even to do the more basic generation of the html code i need.
Here's the page i'm using for all my testing / building:
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>xml test table</title>
<script>
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","SWPlanetData.xml",false);
xmlhttp.send();
swDoc=xmlhttp.responseXML;
var s=swDoc.getElementsByTagName("planet");
</script>
</head>
<body>
<div class="planets-info-container">
<script>
for (i=0;i<s.length;i++)
{
var plName
= s[i].getElementsByTagName("planetName")[0].childNodes[0].nodeValue;
var plDesc
= s[i].getElementsByTagName("description")[0].childNodes[0].nodeValue;
var plUrl
= s[i].getElementsByTagName("linkUrl")[0].childNodes[0].nodeValue;
var plUrlTxt
= s[i].getElementsByTagName("linkText")[0].childNodes[0].nodeValue;
var plShowsList
= s[i].getElementsByTagName("show");
var plGamesList
= s[i].getElementsByTagName("videoGame");
// test section
var test = ''
test += '<div><table border = "1">\n' +
'<tr><td>' + s[i].getElementsByTagName("showText")[0].childNodes[0].nodeValue
+ '</td><td>' + s[i].getElementsByTagName("showUrl")[0].childNodes[0].nodeValue + '</td></tr>'
+ '<tr><td>' + s[i].getElementsByTagName("gameText")[0].childNodes[0].nodeValue + '</td><td>'
+ s[i].getElementsByTagName("gameUrl")[0].childNodes[0].nodeValue + '</td></tr>'
+ '</tr></table></div>'
document.write(test);
document.close();
// end section
document.write("<div class=\"planet-info-container\" id=\""+plName+"-container\">");
document.write("<div class=\"name-row\"><div class=\"planet-name\">"+plName+"</div></div>");
document.write("<div class=\"desc-row\">");
document.write("<div class=\"planet-desc\">"+plDesc+"</div>");
document.write("</div>");
document.write("<div class=\"appearances-row\"><ol class=\"shows\"><li>shows list</li>");
for(j=0;j<plShows.length;j++){
document.write("nested for");
var showUrl = s[i].getElementsByTagName("showUrl")[j].childNodes[0].nodeValue;
var showText = s[i].getElementByTagName("showText")[j].childNodes[0].nodeValue;
document.write("<li><a href=\""+showUrl+"\">"+showText+"</a></li>");
}
document.write("</ol><ol class=\"games\"> games list");
for(j=0;j<s[i].getElementByTagName("videoGame").length;j++){
var gameUrl = s[i].getElementsByTagName("gameUrl")[j].childNodes[0].nodeValue;
var gameText = s[i].getElementByTagName("gameText")[j].childNodes[0].nodeValue;
document.write("<li><a href=\""+gameUrl+"\">"+gameText+"</a></li>");
}
document.write("</ol></div>");
document.write("<div class=\"locs-row\">");
document.write("</div>");
document.write("<div class=\"races-row\">");
document.write("</div>");
document.write("<div class=\"chars-row\">");
document.write("</div>");
document.write("<div class=\"links-row\">");
document.write("<div class=\""+plName+"-link\"><a href=\""+plUrl+"\">"+plUrlTxt+"</a></div>");
document.write("</div>");
document.write("</div><br />");
}
</script>
</div>
</body>
the code breaks at the nested for loop at the end, where it finished the document.write and prints "shows list" to the page, but then never gets to the document.write inside.
if it helps, the xml contains a list of planets from the star wars universe organized like this:
<planets>
<planet>
<planetName>planet</planetName>
<description>some text</description>
<appearances>
<show>
<showUrl>url</showUrl>
<showText>hyperlink text</showText>
</show>
<videoGame>
<gameUrl>url</gameUrl>
<gameText>hyperlink text</gameText>
</videoGame>
</appearances>
<locationsOfInterest>
<location>location name</location>
</locationsOfInterest>
<famousCharactersRelatedTo>
<character>a character</character>
</famousCharactersRelatedTo>
<externalLinks>
<link>
<linkUrl>url</linkUrl>
<linkText>hyperlink text</linkText>
</link>
</externalLinks>
</planet>
edit: i made this harder than it had to be by trying to cut the code down to reduce clutter, but i left out some important things / misordered what i put in, so i replaced the code i had before with the entire page as-is.
edit again: i've made some progress, but i'm still having trouble with the nested loops. it will enter the first one, but breaks before getting all the way through the first iteration on setting the second var:
var showText = s[i].getElementsByTagName("showText")[j].childNodes[0].nodeValue;
can anyone see why this would break?

j<plShows.lengthdid you meanj<plShowsArr.length?var plShowsArr = s[i].getElementsByTagName("show");where does i come from[i]from the line Marcus mentioned, as well as removing the[i]from the line succeeding it.