natie769
01-27-2009, 05:37 PM
I have this Javascript running for parsing an XML file, but it only displays the first item in the XML file....I'm sure its something simple I'm missing.
<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("equipment.xml");
document.write("<table cellpadding='10' width='756px'>");
document.write("<tr>");
document.write("<td>");
document.write("Manufacturer");
document.write("</td>");
document.write("<td>");
document.write("Model");
document.write("</td>");
document.write("<td>");
document.write("Year");
document.write("</td>");
document.write("<td>");
document.write("Equipment");
document.write("</td>");
document.write("<td>");
document.write("Price");
document.write("</td>");
document.write("<td>");
document.write("Options");
document.write("</td>");
document.write("<td>");
document.write("Photos");
document.write("</td>");
document.write("</tr>");
var x=xmlDoc.getElementsByTagName("Activities");
for (i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Manufacturer")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Model")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Year")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Equipment")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Options")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Photos")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
This is my XML schema:
<Activities>
<Activity></Activity>
<Activity></Activity>
<Activity></Activity>
</Activities>
<script type="text/javascript">
var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument("","",null);
}
else
{
alert('Your browser cannot handle this script');
}
if (xmlDoc!=null)
{
xmlDoc.async=false;
xmlDoc.load("equipment.xml");
document.write("<table cellpadding='10' width='756px'>");
document.write("<tr>");
document.write("<td>");
document.write("Manufacturer");
document.write("</td>");
document.write("<td>");
document.write("Model");
document.write("</td>");
document.write("<td>");
document.write("Year");
document.write("</td>");
document.write("<td>");
document.write("Equipment");
document.write("</td>");
document.write("<td>");
document.write("Price");
document.write("</td>");
document.write("<td>");
document.write("Options");
document.write("</td>");
document.write("<td>");
document.write("Photos");
document.write("</td>");
document.write("</tr>");
var x=xmlDoc.getElementsByTagName("Activities");
for (i=0;i<x.length;i++)
{
document.write("<tr>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Manufacturer")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Model")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Year")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Equipment")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Options")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("<td>");
document.write(
x[i].getElementsByTagName("Photos")[0].childNodes[0].nodeValue);
document.write("</td>");
document.write("</tr>");
}
document.write("</table>");
}
</script>
This is my XML schema:
<Activities>
<Activity></Activity>
<Activity></Activity>
<Activity></Activity>
</Activities>