JS中封裝解析xml的代碼,以及實例應用

1。JS中封裝解析xml的代碼,以及實例應用。 //類的構造,傳入xml文檔和需要處理的標籤名稱 function DataSet(xmldoc, tagLabel) { this.rootObj = xmldoc.getElementsByTagName(tagLabel) //3個方法 this.getCount = getCount this.getData = getData this.getAttribute = getAttribute } function getCount(){ return this.rootObj.length } function getData(index, tagName){ if (index >= this.count) return "index overflow" var node = this.rootObj[index] var str = node.getElementsByTagName(tagName)[0].firstChild.data return str } function getAttribute(index, tagName) { if (index >= this.count) return "index overflow" var node = this.rootObj[index] var str = node.getAttribute(tagName) return str } //如何使用DataSet類 function updateByXML(xmlDoc) { var employeeDS = new DataSet(xmlDoc,"employee"); //關心的標籤名稱 var count = employeeDS.getCount() for(i=0;i Programmer 32768 無業遊民 70000 哈爾濱CEO 100000 2。操縱DOM,創建table,顯示獲得的數據 function deleteOldTable() { delRow = document.getElementsByTagName("table").length //此句僅在本例中使用,因爲本例中已經有一個table了,因此不能刪除,需要根據情況變化一下2005.11.17 if(delRow == 1) return var node = document.getElementsByTagName("table")[delRow-1]; //表格 var c = node.childNodes.length for(i=0;i
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章