我有一个xml文件;格式如下:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<menu>
<id>1</id>
<name>小学</name>
</menu>
<menu>
<id>2</id>
<name>初中</name>
</menu>
<menu>
<id>3</id>
<name>高中</name>
</menu>
<menu>
<id>4</id>
<name>大学</name>
</menu>
</root>
每个节点下面都还有子结点,但是是通过js动态读取的,在我读取后咋样在原来的主节点下面添加上他的子节点啊!?我自己写了一个,但是他添加后就把原来的覆盖调了!希望大家来看看啊!指教一哈!如果那个有这一方面的源码或者是资料,希望给我分享一哈!~~急待解决~~~
下面是我自己写的html代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>资源管理器</title>
<script language="javascript" src="js/MakeTree.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
var MenuId;
var MenuName;
function FillRes(ResMenuId)
{
document.getElementById("Res").innerHTML=getSubject(ResMenuId,"");
}
function LoadMenu(pid)
{
document.getElementById("Tree").innerHTML=MakeTree(pid);
}
function Domore(pid)
{
document.getElementById("Res").innerHTML=getSubject(pid,"");
document.getElementById(pid).innerHTML=MakeTree(pid);
}
</script>
<style type="text/css">
<!--
#tools {
position:absolute;
width:100%;
height:30px;
z-index:1;
left: 0px;
top: 0px;
}
#Tree {
position:absolute;
width:20%;
height:500px;
z-index:2;
left: 0px;
top: 30px;
}
#Res {
position:absolute;
width:80%;
height:500px;
z-index:3;
left: 20%;
top: 30px;
}
#Layer1 {
position:absolute;
width:100%;
height:30px;
z-index:4;
left: 0px;
top: 530px;
}
-->
</style>
</head>
<body onload="LoadMenu(0)">
<div id="tools">放置工具栏</div>
<div id="Tree">
</div>
<div id="Res">资源块</div>
<div id="Layer1">状态栏</div>
</body>
</html>
maketree.js
var MenuId;
var MenuName;
var menu="";
function MakeTree(id)
{
menu="";
alert(id);
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("http://localhost/GetMenuListByParentId.aspx?id="+id);//该页面生成xml文件
if(xmlDoc.parseError.errorCode != 0)
{
alert(xmlDoc.parseError.reason);
return;
}
else
{
var nodes=xmlDoc.documentElement.childNodes;
for(var i=0;i<nodes.length;i++)
{
if(nodes(i).nodeName=="menu")
{
MenuId=nodes(i).selectNodes("id")(0).text;
MenuName=nodes(i).selectNodes("name")(0).text;
// menu+="<li id="+MenuId+">"+"<a href=javascript:FillRes("+MenuId+")>"+MenuName+"</a></li>";
menu+="<div id='"+MenuId+"'><a href=javascript:Domore("+MenuId+")>"+MenuName+"</a></div>"
}
}
}
alert(menu);
delete(xmlDoc);
return menu;
}