javascript - Writing XML file with HTML -
i trying utilize xml file, , write out info on website using html. if school project, , teacher spesifically told utilize xml , html. html contains code, pictures, text etc, , works perfectly. tried set xml code within tag, , write out. xml file table info favourite basketballball players.
i have searched through net couple of days now, , couldnt find info topic. visited w3schools site , tried using info given there.
the problem when utilize have done there, seek expand it, , create work own tags, wont work, @ all! example, when have 2 tags in xml file, , seek write out, works. seek add together 1 more tag, , whole thing shuts down. appears little black square.
here xml code:
<?xml version="1.0" encoding="utf-8"?> <basketballplayers> <player> <name>steve nash</name> <college>santa clara</college> <team>la lakers</team> </player> <player> <name>ricky rubio</name> <college>did not attend</college> <team>minnesota timberwolves</team> </player> <player> <name>michael jordan</name> <college>north carolina</college> <team>chicago bulls</team> </player> </basketballplayers>
and here html code, xml stuff:
<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", "proving.xml", false); xmlhttp.send(); xmldoc = xmlhttp.responsexml; document.write("<table border='1'>"); var x = xmldoc.getelementsbytagname("player"); (i = 0; < x.length; i++) { document.write("<tr><td>"); document.write(x[i].getelementsbytagname("name")[0].childnodes[0].nodevalue); document.write("</td><td>"); document.write(x[i].getelementsbytagname("college")[0].childnodes[0].nodevalue); document.write("</td></tr>"); document.write(x[i].getelementsbytagname("team")[0].childnodes[0].nodevalue); document.write("</td></tr>"); } document.write("</table>"); </script> </div>
utilizing jquery js library ,
try
$.get("proving.xml", null, null, "xml") .done(function (xml, textstatus, jqxhr) { $("body").append("<table id=result border=1></table>"); $(xml).find("player *").each(function (i, el) { $("#result").append("<tr><td>" + el.textcontent + "</td></tr>") }) })
jsfiddle http://jsfiddle.net/guest271314/w6nx71pd/
javascript jquery html css xml
No comments:
Post a Comment