I'm having trouble figuring out why this isn't looping. Just for testing purposes, I have included just two equipment tags that have all this information within this tag. Equipment-syndication is the main tag here. Here is my code:
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else // for IE 5/6
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","http://ift.tt/1GNAwbx",false);
xhttp.send();
xmlDoc=xhttp.responseXML;
document.write("XML document loaded into an XML DOM Object.");
document.write("<table><tr><th>Equipment ID</th><th>Price</th><th>Dealer Name</th><th>Category</th><th>Features</th><th>Images</th></tr>");
var x=xmlDoc.getElementsByTagName("equipment-syndication");
for (i=0;i<x.length;i++)
{
document.write("<tr><td>");
document.write(x[i].getElementsByTagName("equipment")[0].getAttribute('id'));
document.write("</td><td>");
document.write(x[i].getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("contact")[0].getAttribute('first-name'));
document.write(x[i].getElementsByTagName("contact")[0].getAttribute('last-name'));
document.write("</td><td>");
document.write(x[i].getElementsByTagName("category-class")[0].getAttribute('name'));
document.write("</td><td>");
document.write(x[i].getElementsByTagName("category-class")[0].getAttribute('name'));
document.write("</td><td>");
document.write('<img src="'+x[i].getElementsByTagName("photo")[0].childNodes[0].nodeValue+'"><br>');
document.write("</td></tr>");
}
document.write("</table>");
Now I know everything is correct because I can see the xml file being generated on the front end. I can see the ID, the name, an image... All that stuff. Am I getting the loop wrong? It's supposed to add another row if there is more than one "Equipment" element tag, right?
Here is the basic structure of the xml file I'm working with:
<equipment-syndication>
<equipment id="">
<price></price>
<product></product>
<features></features>
<photos></photos>
</equipment>
<equipment id="">
<price></price>
<product></product>
<features></features>
<photos></photos>
</equipment>
</equipment-syndication>
Aucun commentaire:
Enregistrer un commentaire