XML data was displaying via Javascript on page, now is not
A page displaying items from a database was reading data in and displaying it properly in a table, and apparently stopped doing so when I changed the xml tags in the xml file. But this continued when I changed them in the Javascript script. The HTML loads and displays properly, including the table header.
The HTML page is (The relevant script is shown below.)
TheXML page is (The text of the file is shown at the bottom of this post.)
I built this off of a W3 schools tutorial at (this page displays the code of the XML data) and its application editor at
Here is the relevant Javascript:
Quote:</thead>
<script type="text/javascript">
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else // Internet Explorer 5/6
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","saleitems/catalog.xml");
xhttp.send("");
xmlDoc=xhttp.responseXML;
document.write(xmlDoc);
try {
j=1;
document.write("");
var x=xmlDoc.getElementsByTagName("saleitem");
} catch {
document.write("\n",err.exception,"\n");
}
alert(x.length);
for (i=0;i<x.length;i++)
{
//alternate row colors
if (j==0) {
rowClass = "main";
j = 1;
} else {
rowClass = "alt";
j = 0;
}
document.write("<tr class='",rowClass,"'><td>");
document.write("<b>");
document.write(x.getElementsByTagName("itemtype")[0].childNodes[0].nodeValue);
document.write("</b>");
document.write("</td><td>");
document.write(x.getElementsByTagName("itemname")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("brand")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("model")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("year")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("length")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("width")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("height")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("weight")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write("$",x.getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("description")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write('<img src="images/');
document.write(x.getElementsByTagName("picture")[0].childNodes[0].nodeValue);
document.write('" />');
alert(i+"..."+x.getElementsByTagName("itemtype")[0].childNodes[0].nodeValue+"..."+x.getElementsByTagName("picture")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
</script>
</table>
Here is the text of the XML file. The data was displaying properly even without a css stylesheet, which the tutorial example does not seem torely on in any way shown.
Quote:<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href=""?>
<catalog>
<saleitem>
<itemid>1</itemid>
<itemtype>Tugboat</itemtype>
<itemname>Valiant</itemname>
<brand>Columbia Tugboat Company</brand>
<model>Warpspeed</model>
<year>1950</year>
<length>95 ft</length>
<width>na</width>
<height>na</height>
<weight>na</weight>
<price>40,000.00</price>
<description>This 95 foot long tugboat has two stories on deck, and it RUNS FAR, RUNS FAST.</description>
<picture>sometugboat.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
<saleitem>
<itemid>2</itemid>
<itemtype>Entertainment Center</itemtype>
<itemname>na</itemname>
<brand>Downtown Home Furnishings</brand>
<model>na</model>
<year>1985</year>
<length>na</length>
<width>na</width>
<height>na</height>
<weight>na</weight>
<price>5.00</price>
<description>This entertainment center was given to us by someone who moved to Virginia and could not take it with them.</description>
<picture>someentertainmentcenter.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
<saleitem>
<itemid>3</itemid>
<itemtype>Television</itemtype>
<itemname>na</itemname>
<brand>Sony</brand>
<model>W569-A</model>
<year>1996</year>
<length>na</length>
<width> </width>
<height>na</height>
<weight>na</weight>
<price>10.00</price>
<description>This television has a 19 inch screen and has medium resolution but is otherwise reliable.</description>
<picture>sometelevision.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
<saleitem>
<itemid>4</itemid>
<itemtype>VCR</itemtype>
<itemname>na</itemname>
<brand>Zenix</brand>
<model>YF812-F34</model>
<year>1999</year>
<length>na</length>
<width>na</width>
<height>na</height>
<weight>na</weight>
<price>5.00</price>
<description>This 4-head VCR has channel skipping capability.</description>
<picture>someVCR.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
<saleitem>
<itemid>5</itemid>
<itemtype>Desk</itemtype>
<itemname>na</itemname>
<brand>na</brand>
<model>na</model>
<year>na</year>
<length>na</length>
<width>na</width>
<height>na</height>
<weight>na</weight>
<price>10.00</price>
<description>This 6-drawer wooden desk has a few scratches but the drawers have been restored to smooth function.</description>
<picture>someWooden_desk.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
</catalog>
Visit this user's website Find all posts by this user
A page displaying items from a database was reading data in and displaying it properly in a table, and apparently stopped doing so when I changed the xml tags in the xml file. But this continued when I changed them in the Javascript script. The HTML loads and displays properly, including the table header.
The HTML page is (The relevant script is shown below.)
TheXML page is (The text of the file is shown at the bottom of this post.)
I built this off of a W3 schools tutorial at (this page displays the code of the XML data) and its application editor at
Here is the relevant Javascript:
Quote:</thead>
<script type="text/javascript">
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else // Internet Explorer 5/6
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET","saleitems/catalog.xml");
xhttp.send("");
xmlDoc=xhttp.responseXML;
document.write(xmlDoc);
try {
j=1;
document.write("");
var x=xmlDoc.getElementsByTagName("saleitem");
} catch {
document.write("\n",err.exception,"\n");
}
alert(x.length);
for (i=0;i<x.length;i++)
{
//alternate row colors
if (j==0) {
rowClass = "main";
j = 1;
} else {
rowClass = "alt";
j = 0;
}
document.write("<tr class='",rowClass,"'><td>");
document.write("<b>");
document.write(x.getElementsByTagName("itemtype")[0].childNodes[0].nodeValue);
document.write("</b>");
document.write("</td><td>");
document.write(x.getElementsByTagName("itemname")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("brand")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("model")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("year")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("length")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("width")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("height")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("weight")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write("$",x.getElementsByTagName("price")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x.getElementsByTagName("description")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write('<img src="images/');
document.write(x.getElementsByTagName("picture")[0].childNodes[0].nodeValue);
document.write('" />');
alert(i+"..."+x.getElementsByTagName("itemtype")[0].childNodes[0].nodeValue+"..."+x.getElementsByTagName("picture")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
</script>
</table>
Here is the text of the XML file. The data was displaying properly even without a css stylesheet, which the tutorial example does not seem torely on in any way shown.
Quote:<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href=""?>
<catalog>
<saleitem>
<itemid>1</itemid>
<itemtype>Tugboat</itemtype>
<itemname>Valiant</itemname>
<brand>Columbia Tugboat Company</brand>
<model>Warpspeed</model>
<year>1950</year>
<length>95 ft</length>
<width>na</width>
<height>na</height>
<weight>na</weight>
<price>40,000.00</price>
<description>This 95 foot long tugboat has two stories on deck, and it RUNS FAR, RUNS FAST.</description>
<picture>sometugboat.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
<saleitem>
<itemid>2</itemid>
<itemtype>Entertainment Center</itemtype>
<itemname>na</itemname>
<brand>Downtown Home Furnishings</brand>
<model>na</model>
<year>1985</year>
<length>na</length>
<width>na</width>
<height>na</height>
<weight>na</weight>
<price>5.00</price>
<description>This entertainment center was given to us by someone who moved to Virginia and could not take it with them.</description>
<picture>someentertainmentcenter.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
<saleitem>
<itemid>3</itemid>
<itemtype>Television</itemtype>
<itemname>na</itemname>
<brand>Sony</brand>
<model>W569-A</model>
<year>1996</year>
<length>na</length>
<width> </width>
<height>na</height>
<weight>na</weight>
<price>10.00</price>
<description>This television has a 19 inch screen and has medium resolution but is otherwise reliable.</description>
<picture>sometelevision.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
<saleitem>
<itemid>4</itemid>
<itemtype>VCR</itemtype>
<itemname>na</itemname>
<brand>Zenix</brand>
<model>YF812-F34</model>
<year>1999</year>
<length>na</length>
<width>na</width>
<height>na</height>
<weight>na</weight>
<price>5.00</price>
<description>This 4-head VCR has channel skipping capability.</description>
<picture>someVCR.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
<saleitem>
<itemid>5</itemid>
<itemtype>Desk</itemtype>
<itemname>na</itemname>
<brand>na</brand>
<model>na</model>
<year>na</year>
<length>na</length>
<width>na</width>
<height>na</height>
<weight>na</weight>
<price>10.00</price>
<description>This 6-drawer wooden desk has a few scratches but the drawers have been restored to smooth function.</description>
<picture>someWooden_desk.jpg</picture>
<employee>na</employee>
<datestamp>na</datestamp>
</saleitem>
</catalog>
Visit this user's website Find all posts by this user