XML & Javascript: cannot get this simple demo to work

MooMoo

New Member
Hi I'm trying to loop through an XML file and print out the results in a table. Now I have an example from W3C Schools which is very similar and it works, but substituting my file and values stops it working. I would appreciate it someone could point me to what I am dong wrong.So this is the W3C example in full: \[code\]<!DOCTYPE html><html><body><script type="text/javascript">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","cd_catalog.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>");var x=xmlDoc.getElementsByTagName("CD");for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x.getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x.getElementsByTagName("TITLE")[0].childNodes[0].nodeValue); document.write("</td></tr>"); }document.write("</table>");</script></body></html>\[/code\]My code differs as follows:\[code\]xmlhttp.open("GET","data.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML; document.write("<table border='1'>");var x=xmlDoc.getElementsByTagName("festival");for (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x.getElementsByTagName("title")[0].childNodes[0].nodeValue); document.write("</td><td>"); document.write(x.getElementsByTagName("artist")[0].childNodes[0].nodeValue); document.write("</td></tr>"); }\[/code\]and the two XML files are at http://www.holtworth.net/xml/data.xml (my XML) and http://www.holtworth.net/xml/cd_catalog.xml (original)
 
Back
Top