您的位置:首页 > Web前端 > JavaScript

JS中封装解析xml的代码,以及实例应用

2007-07-03 20:10 991 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: