JS操作XML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>t1.html</title> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="this is my page"> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <script type="text/javascript"> try { xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) { try { xmlDoc = document.implementation.createDocument("", "", null); } catch (e) { alert(e.message); } } try { xmlDoc.async = false; xmlDoc.load("xmls/students.xml"); var output = ""; var nodes = xmlDoc.getElementsByTagName("student"); for ( var i = 0; i < nodes.length; i++) { output += "<" + nodes[i].nodeName; for ( var j = 0; j < nodes[i].attributes.length; j++) { output += "" + nodes[i].attributes[j].nodeName+"=""+nodes[i].getAttribute(nodes[i].attributes[j].nodeName)+"""; output+="><br />"; for(var k=0;k<nodes[i].childNodes.length;k++){ output += "<" + nodes[i].childNodes[k].nodeName+">"; output += nodes[i].childNodes[k].childNodes[0].nodeValue; output += "<" + nodes[i].childNodes[k].nodeName+"/><br />"; } } output+="</"+nodes[i].nodeName+"><br />"; } document.writeln(output); } catch (e) { alert(e.message); } </script> </head> <body> This is my HTML page. <br> </body> </html>


<?xml version="1.0" encoding="UTF-8"?> <students> <student id="scce001"> <name>Lan</name> <class>G3T05</class> <sex>famale</sex> <birthday> <year>1990</year> <month>01</month> <day>21</day> </birthday> </student> <student id="scce002"> <name>TuDou</name> <class>G3T05</class> <sex>male</sex> <birthday> <year>1989</year> <month>01</month> <day>24</day> </birthday> </student> <student id="scce003"> <name>Lee</name> <class>G3T05</class> <sex>male</sex> <birthday> <year>1989</year> <month>09</month> <day>03</day> </birthday> </student> </students>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值