js將xml資料寫入table表格
本章節分享一段程式碼例項,它實現了將xml中的資料寫入table表格的功能。
xml程式碼如下:
[XML] 純文字檢視 複製程式碼<?xml version="1.0" standalone="yes"?> <student> <stuinfo> <stuName>螞蟻部落一</stuName> <stuSex>男</stuSex> <stuAge>18</stuAge> </stuinfo> <stuinfo> <stuName>螞蟻部落二</stuName> <stuSex>男</stuSex> <stuAge>31</stuAge> </stuinfo> <stuinfo> <stuName>螞蟻部落三</stuName> <stuSex>男</stuSex> <stuAge>22</stuAge> </stuinfo> <stuinfo> <stuName>螞蟻部落四</stuName> <stuSex>女</stuSex> <stuAge>25</stuAge> </stuinfo> <stuinfo> <stuName>螞蟻部落五</stuName> <stuSex>男 </stuSex> <stuAge>32</stuAge> </stuinfo> <stuinfo> <stuName>螞蟻部落六</stuName> <stuSex>男</stuSex> <stuAge>28</stuAge> </stuinfo> <stuinfo> <stuName>螞蟻部落七</stuName> <stuSex>女</stuSex> <stuAge>23</stuAge> </stuinfo> <stuinfo> <stuName>螞蟻部落八</stuName> <stuSex>女</stuSex> <stuAge>22</stuAge> </stuinfo> </student>
js程式碼如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script type="text/javascript"> function loadXMLDoc(dname) { if (window.XMLHttpRequest) { xhttp = new XMLHttpRequest(); }else { xhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET", dname, false); xhttp.send(""); return xhttp.responseXML; } function ReadXml() { var xmldoc = loadXMLDoc("Student.xml"); //獲得指定節點 var divmsg = document.getElementById("xmlMsg"); var msg = "<table border='1' id='mytable'><tr><th>姓名</th><th>性別</th><th>年齡</th><tr>"; var nodes = xmldoc.getElementsByTagName("stuinfo"); for (var i = 0; i < nodes.length; i++) { msg += "<tr>"; msg += "<td>" + nodes[i].getElementsByTagName("stuName")[0].firstChild.nodeValue + "</td>"; msg += "<td>" + nodes[i].getElementsByTagName("stuSex")[0].firstChild.nodeValue + "</td>"; msg += "<td>" + nodes[i].getElementsByTagName("stuAge")[0].firstChild.nodeValue + "</td>"; msg += "</tr>"; } msg += "</table>"; divmsg.innerHTML = msg; } </script> </head> <body> <form id="form1"> <div> <input type="button" value="JS讀取XML" onclick="ReadXml()" /><br /> <div id="xmlMsg"> </div> </div> </form> </body> </html>
相關文章
- js 將xml轉換為table表格簡單程式碼例項JSXML
- 將XML匯入資料庫XML資料庫
- 將excel表格匯入資料庫Excel資料庫
- 如何將 JSON, Text, XML, CSV 資料檔案匯入 MySQLJSONXMLMySql
- java怎麼將excel表格資料匯入資料庫JavaExcel資料庫
- 如何將 EXCEL 資料寫入資料庫Excel資料庫
- java實現將excel表格資料解析成JSONArrayJavaExcelJSON
- 將表格資料匯入Excel表程式碼例項Excel
- js table表格排序程式碼例項JS排序
- bootsrap table 表格載入完整 post-body.bs.tableboot
- 檢索table表格資料程式碼例項
- 資料庫表格轉換成XML格式方法!資料庫XML
- 將table表格內容匯入到word或者Excel程式碼例項Excel
- Mysql增量寫入Hdfs(一) --將Mysql資料寫入Kafka TopicMySqlKafka
- js如何動態建立一個table表格JS
- js將表格匯入到Execel表例項程式碼JS
- javascript動態建立table表格並新增資料程式碼JavaScript
- js table表格操作大全程式碼例項JS
- 讀取JSON資料存入表格JSON
- 【Node.js】寫一個資料自動整理成表格的指令碼Node.js指令碼
- 極簡 Node.js 入門 - 3.4 資料夾寫入Node.js
- vue + element UI 中 el-table 資料匯出Excel表格VueUIExcel
- CSS table表格美化CSS
- tpextbuilder- Table 表格UI
- HTML <table>表格概述HTML
- 將資料庫中資料匯出為excel表格資料庫Excel
- 以太坊·將資料寫入到區塊鏈中區塊鏈
- Yii將需要的log寫入到資料庫中資料庫
- 編寫更快地載入表格
- MySQL load xml載入資料MySqlXML
- 【java web】--ojdbc匯入xml資料JavaWebJDBCXML
- NPM酷庫051:xml2js,解析XML格式資料NPMXMLJS
- js獲取table表格指定行列td單元格內容JS
- js迭代table表格的行和列程式碼例項JS
- JSP筆記-XML 資料處理JS筆記XML
- 資料格式之戰:JSON vs XMLJSONXML
- HTML table表格結構HTML
- python如何將資料寫入本地txt文字檔案Python