javascript XML数据显示为HTML一例
person.htm:
person.xml:
代码如下:
<html> <body> <script type="text/javascript"> var xmlDoc=null; if (window.ActiveXObject) { // for IE xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } else if (document.implementation.createDocument) { //for Mozilla, Firefox, Opera, xmlDoc=document.implementation.createDocument("","",null); } else { alert('Your browser cannot handle this script'); } if (xmlDoc!=null) { xmlDoc.async=false; xmlDoc.load("person.xml"); document.write("<table border='1'>"); var x=xmlDoc.getElementsByTagName("person"); for (i=0;i<x.length;i++) { document.write("<tr>"); document.write("<td>"); document.write( x[i].getElementsByTagName("myname")[0].childNodes[0].nodeValue); document.write("</td>"); document.write("<td>"); document.write( x[i].getElementsByTagName("myid")[0].childNodes[0].nodeValue); document.write("</td>"); document.write("</tr>"); } document.write("</table>"); } </script> </body> </html>
person.xml:
代码如下:
<?xml version="1.0" encoding="utf-8"?> <root> <person> <myname>chwuweig</myname> <myid>123456</myid> </person> <person> <myname>cig</myname> <myid>526636</myid> </person> <person> <myname>chwg</myname> <myid>524216</myid> </person> </root>
相关推荐
lupeng 2020-11-14
sjcheck 2020-11-10
sjcheck 2020-11-03
meylovezn 2020-08-28
owhile 2020-08-18
Francismingren 2020-08-17
pythonclass 2020-07-29
sunzhihaofuture 2020-07-19
爱读书的旅行者 2020-07-07
行吟阁 2020-07-05
tianqi 2020-07-05
行吟阁 2020-07-04
冰蝶 2020-07-04
lyg0 2020-07-04
owhile 2020-07-04
opspider 2020-06-28
lengyu0 2020-06-28
tianqi 2020-06-21
dadaooxx 2020-06-16