Display XML with Javascript -
here's sample xml code:
<?xml version="1.0" encoding="utf-8"?> <entry n="5"> <form type="lemma">hi <orth xml:lang="syc">ܐܳܐܱܪ</orth> </form> <gramgrp> <gram type="pos">noun</gram> <gram type="gender">commongender</gram> </gramgrp> <etym> <lang>greek</lang> <mentioned>ἀήρ</mentioned> </etym> <form type="inflected" ana="#n_pl"> <orth xml:lang="syc">ܐܰܐܷܪ̈ܰܣ</orth> </form> <sense> <cit type="translation" xml:lang="en"> <quote>air, breeze</quote> </cit> </sense> </entry>
i need display in formatted fashion, depending on tags. i've followed code found @ w3schools http://www.w3schools.com/xml/xml_applications.asp, changing filename , tagname values necessary. in end... nothing happens, blank screen. have server running this, btw.
javascript:
<script> function loadxmldoc() { var xmlhttp = new xmlhttprequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { myfunction(xmlhttp); } } xmlhttp.open("get", "dict.xml", true); xmlhttp.send(); } function myfunction(xml) { var i; var xmldoc = xml.responsexml; var table="<tr><th>artist</th><th>title</th></tr>"; var x = xmldoc.getelementsbytagname("entry"); (i = 0; <x.length; i++) { table += "<tr><td>" + x[i].getelementsbytagname("lemma")[0].childnodes[0].nodevalue + "</td><td>" + x[i].getelementsbytagname("sense")[0].childnodes[0].nodevalue + "</td></tr>"; } document.getelementbyid("demo").innerhtml = table; } </script>
i worry getting formatting correct , tags represented afterwards, need working @ all, first.
Comments
Post a Comment