XML Data not showing up in HTML file -
i have xml file titled "xmldata.xml" located in same folder index.html file. have code display xml data on html page not working. ideas?
<script> if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.open("get","xmldata.xml",false); xmlhttp.send(); xmldoc=xmlhttp.responsexml; document.write("<table border='1'>"); var x=xmldoc.getelementsbytagname("company"); (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getelementsbytagname("c_id")[0].childnodes[0].nodevalue); document.write("</td><td>"); document.write(x[i].getelementsbytagname("c_name")[0].childnodes[0].nodevalue); document.write("</td></tr>"); } document.write("</table>"); </script>
your code works fine on own machine.
i used following xml code xmldata.xml:
<company> <c_id> 0 </c_id> <c_name>moo</c_name> </company>
i used following html/javascript code:
<html> <script> if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.open("get","xmldata.xml",false); xmlhttp.send(); xmldoc=xmlhttp.responsexml; document.write("<table border='1'>"); var x=xmldoc.getelementsbytagname("company"); (i=0;i<x.length;i++) { document.write("<tr><td>"); document.write(x[i].getelementsbytagname("c_id")[0].childnodes[0].nodevalue); document.write("</td><td>"); document.write(x[i].getelementsbytagname("c_name")[0].childnodes[0].nodevalue); document.write("</td></tr>"); } document.write("</table>"); </script> <body> </body> </html>
Comments
Post a Comment