/***************************** *ElementNode对象,继承自抽象对象TreeNode *新增属性: *_nodeName 节点名称 ******************************/ var ElementNode = function(node,level) { TreeNode.apply(this,arguments); this._nodeName = XMLDom.getAttribute(node,"name") ? XMLDom.getAttribute(node,"name") : ""; this.toHTML = function(){ var result = ""; if(this.isLast) result += "
else result += "
result += " id='"+this.id+"_join' Onclick=\"JXTree.changeState('"+this.id+"')\">
"+this._nodeName+"
"; return result; } }
/***************************** *TexNode对象,继承自抽象对象TreeNode *属性和TreeNode一样 *新增属性: *_nodeValue 节点值 ******************************/ var TextNode = function(node,level) { TreeNode.apply(this,arguments); this._nodeValue = node.firstChild.nodeValue; this.toHTML = function(){ var result = ""; if(this.isLast) result += "
"; else result += "
"; result += ""+this._nodeValue+"
"; return result; } }
/**********Node 节点构建结束,开始解释XML文件************/
var DOMRoot=XMLDom.loadXML(xmlURL).documentElement;//同步加载XML文件 var level = -1;//root节点level var stack = new Array(1); result.push("
"+XMLDom.getAttribute(DOMRoot,"name")+"
"); //解释xml文件内容成树状态展开的HTML代码,递归调用 this.parseXML = function(node){ stack.push(level); level++; var element = new ElementNode(node,level); var elements = node.childNodes; if(level != 0){ if(element.isLast) result.push("
"); else result.push("
"); } for(var i=0;i if(elements.item(i).nodeName == "item"){//节点为树叶 var textNode = new TextNode(elements.item(i),level); result.push(textNode.toHTML()); textNode = null;//及时释放对象 } else if(elements.item(i).nodeType ==1){//节点为树枝 var elementNode = new ElementNode(elements.item(i),level); result.push(elementNode.toHTML()); elementNode = null;//及时释放对象 this.parseXML(elements.item(i)); } } if(level != 0)result.push("