将xml内容输出到div中

来源:互联网 发布:淘宝客服怎么知道业绩 编辑:程序博客网 时间:2024/09/21 09:27

note.xml文件结构:

<nooo><note><to>George</to><from>John</from><heading>Reminder</heading><body>Don't forget the meeting!</body></note><note><to>a</to><from>John</from><heading>Reminder</heading><body>Don't forget the meeting!</body></note><note><to>George</to><from>John</from><heading>Reminder</heading><body>Don't forget the meeting!</body></note></nooo>

利用js将xml输出到div中:

<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><style> .aaaa{width: 30%;height: 50px;line-height: 50px;text-align: center;border: 1px solid darkblue;float: left;}</style></head><body>    <div id="xmlid"></div><script>xmltext = new XMLHttpRequest;xmltext.open("GET","note.xml",false);xmltext.send();a = xmltext.responseXML;//document.getElementById("xmlid").innerHTML = a.getElementsByTagName("to")[2].childNodes[0].nodeValue;x = a.getElementsByTagName("note");for(i=0;i<x.length;i++){document.write("<div class='aaaa'>");document.write(x[i].getElementsByTagName("to")[0].childNodes[0].nodeValue);document.write("</div>");document.write("<div class='aaaa'>");document.write(x[i].getElementsByTagName("heading")[0].childNodes[0].nodeValue);document.write("</div>");document.write("<div class='aaaa'>");document.write(x[i].getElementsByTagName("body")[0].childNodes[0].nodeValue);document.write("</div>");}</script></body></html>


1 0
原创粉丝点击