php解析api xml并输出到html页面,怎样操作JS读取xml内容并输出到div内
這次給大家帶來怎樣操作JS讀取xml內容并輸出到div內,操作JS讀取xml內容并輸出到div內的注意事項有哪些,下面就是實戰案例,一起來看一下。
note.xml文件結構:
George
John
Reminder
a
John
Reminder
George
John
Reminder
利用js將xml輸出到p中:
www.jb51.net js讀取xml.aaaa{width: 30%;height: 50px;line-height: 50px;text-align: center;border: 1px solid darkblue;float: left;}
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
{
document.write("
");
document.write(x[i].getElementsByTagName("to")[0].childNodes[0].nodeValue);
document.write("
");document.write("
");
document.write(x[i].getElementsByTagName("heading")[0].childNodes[0].nodeValue);
document.write("
");document.write("
");
document.write(x[i].getElementsByTagName("body")[0].childNodes[0].nodeValue);
document.write("
");}
相信看了本文案例你已經掌握了方法,更多精彩請關注php中文網其它相關文章!
推薦閱讀:
總結
以上是生活随笔為你收集整理的php解析api xml并输出到html页面,怎样操作JS读取xml内容并输出到div内的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 风之大陆哪个区互通
- 下一篇: 动态规划算法php,php算法学习之动态