这个我有Asp + XML的源代码:
基本算法:递归算法,只不过得有xmlDom对象的支持(不用xml,就不必了)
a. asp 源文件
<%@ Language=VBScript %>
<%Option Explicit%>
<!--#include file="Common/Constant.asp" -->
<!--#include file="Common/Function.asp" -->
<%
Response.Buffer=TrueDim m_xmlSourceInfo
Set m_xmlSourceInfo=ResLoadXMLFromString("<Root/>")Subcategories m_xmlSourceInfo.documentElementDim m_xmlhttp
Dim m_intCount '计数变量,标识每一资源,之所以不用ObjId,是因为它太长了,无形中增加用户运行速度Dim i,j,k%>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<meta http-equiv="Content-Type" Content="text/html; charset=gb2312">
<link REL="stylesheet" Type="text/css" Href="LeftTree.css">
<script language="javascript">
//******************************************************************************************************
//鼠标移入当前节点 ---- 增加下划线
function fnMouseOver()
{
var eSrc = window.event.srcElement;
eSrc.style.textDecoration = "underline";
}//******************************************************************************************************
//鼠标移出当前节点
function fnMouseOut()
{
var eSrc = window.event.srcElement;
eSrc.style.textDecoration = "none";
}
</script>
</HEAD>
<BODY onload="fnInit()" style="border-right: 6px solid #BEE294"><table border="0" cellPadding="0" cellSpacing="0">
<%
Dim xmlNodesListm_intCount = 0
If Not m_xmlSourceInfo.SelectSingleNode("./Root/SubCategory") Is Nothing Then
Set xmlNodesList = m_xmlSourceInfo.SelectNodes("./Root/SubCategory")
For i = 0 To xmlNodesList.length - 1
Call MakeHTMLInfo(xmlNodesList(i))
Next
End If
%>
</table></BODY>
</HTML>
<%
'----------------------------------------------------------------------------------------------
'递归函数,生成当前当前节点信息
'----------------------------------------------------------------------------------------------
Sub MakeHTMLInfo(objNode)
Dim m
Dim strObjId,strName,strUrl

m_intCount = m_intCount + 1 '资源计数

strObjId = objNode.SelectSingleNode("./@ObjID").NodeTypedValue
strName = objNode.SelectSingleNode("./@Name").NodeTypedValue
strUrl = objNode.SelectSingleNode("./@URL").NodeTypedValue
If objNode.childNodes.length = 0 Then '叶节点
Response.Write MakeLastNodeHTMLInfo(strObjId,strName,strUrl)
Else '非叶节点
Response.Write MakeNoLastNodeHTMLInfo(strObjId,strName,strUrl)

'循环写出字节点信息
For m = 0 To objNode.childNodes.length - 1
Call MakeHTMLInfo(objNode.childNodes.item(m))
Next

Response.Write "</table></span></td></tr>"
End If
End Sub'----------------------------------------------------------------------------------------------
'生成非叶节点信息
'----------------------------------------------------------------------------------------------
Function MakeNoLastNodeHTMLInfo(strObjId,strName,strUrl)
Dim strHTML

'生成本节点信息
strHTML = "<tr><td nowrap>"

strHTML = strHTML & "<img id=cnlImg" & m_intCount & " name=cnlImg" & m_intCount & " " 
strHTML = strHTML & "src='images/bookClosed.gif' onclick='fnClickImg(" & m_intCount & ")' style='cursor: hand'>"
strHTML = strHTML & "</img>&nbsp;"

strHTML = strHTML & "<span id=cnlName" & m_intCount & " onmouseover='fnMouseOver()' onmouseout='fnMouseOut()' "
strHTML = strHTML & "onclick='fnClickGroups(" & m_intCount & ",""" & strUrl & """)' style='cursor: hand'>"
strHTML = strHTML & strName & "</span>"

strHTML = strHTML & "</td></tr>"

'生成字节点部分信息 ---- 表格头
strHTML = strHTML & "<tr><td nowrap>"
strHTML = strHTML & "<span id=cnlDiv" & m_intCount & " style='DISPLAY: none;'>"
  strHTML = strHTML & "<table border='0' cellPadding='0' cellSpacing='0' style='PADDING-LEFT: 25px;'>"
 
  MakeNoLastNodeHTMLInfo = strHTML
End Function'----------------------------------------------------------------------------------------------
'生成叶节点信息
'----------------------------------------------------------------------------------------------
Function MakeLastNodeHTMLInfo(strObjId,strName,strUrl)
Dim strHTML

'生成本节点信息
strHTML = "<tr><td nowrap>"

strHTML = strHTML & "<img id=cnlImg" & m_intCount & " name=cnlImg" & m_intCount & " " 
strHTML = strHTML & "src='images/paper.gif' onclick=""fnClickLastNode(" & m_intCount & ",'" & strUrl & "'" & ")"" style='cursor: hand'>"
strHTML = strHTML & "</img>&nbsp;"

strHTML = strHTML & "<span id=cnlName" & m_intCount & " onmouseover='fnMouseOver()' onmouseout='fnMouseOut()' "
strHTML = strHTML & "onclick=""fnClickLastNode(" & m_intCount & ",'" & strUrl & "'" & ")"" style='cursor: hand'>"
strHTML = strHTML & strName & "</span>"

strHTML = strHTML & "</td></tr>"

  MakeLastNodeHTMLInfo = strHTML
End Function
%><script language="javascript">
var m_intNowDisplayNodeId; //当前在右边显示的列表节点Id//**********************************************************************************************
//数据初始化
function fnInit()
{
m_intNowDisplayNodeId = -1;
}//**********************************************************************************************
//打开和关闭字节点
function fnClickImg(intIndex)
{
var strImgId = "cnlImg" + intIndex;
var strChildId = "cnlDiv" + intIndex;

if(document.all(strChildId).style.display == "none" ) //以前是关闭的
{
document.all(strImgId).src = "images/BookOpened.gif";
document.all(strChildId).style.display = "block";
}
else
{
document.all(strImgId).src = "images/BookClosed.gif";
document.all(strChildId).style.display = "none";
}
}//**********************************************************************************************
//用户点击了叶节点
function fnClickLastNode(intIndex,strURL)
{
var strNodeNameId = "cnlName" + intIndex;

//改变以前选中的节点显示情式  
if(m_intNowDisplayNodeId != - 1)
{
var strId = "cnlName" + m_intNowDisplayNodeId;
document.all(strId).style.backgroundColor = "";
document.all(strId).style.fontWeight = "";
}

//改变当前选中的节点显示清识
document.all(strNodeNameId).style.backgroundColor = "#81b280";
document.all(strNodeNameId).style.fontWeight = "bold";
m_intNowDisplayNodeId = parseInt(intIndex);

//改变右边的显示形式
window.open(strURL,"maincontent");
}//**********************************************************************************************
//单击了非叶节点文字
function fnClickGroups(intIndex,strURL)
{
fnClickLastNode(intIndex,strURL);
}
</script><%
Sub Subcategories(node)
Dim nodeClsID, sClsID, i
Set nodeClsID=node.selectSingleNode("@ObjID")
If nodeClsID Is Nothing Then
sClsID=""
Else
sClsID=CStr(nodeClsID.nodeTypedValue)
End If
Set nodeClsID=Nothing

Dim xmlSubcategories, nodesSubcategories, nodeSubcategory
Set xmlSubcategories=ResExecStoredProc("res_category_subcategories3", sClsID)

Set nodesSubcategories=xmlSubcategories.selectNodes("Root/SubCategory")
For i=0 To nodesSubcategories.length-1
Set nodeSubcategory=nodesSubcategories.item(i).cloneNode(True)
Subcategories nodeSubcategory
If nodeSubcategory.selectSingleNode("@RootCategoryObjID") Is Nothing Then
nodeSubcategory.selectSingleNode("@URL").nodeValue="Categories/RootCategories.asp?i=" & nodeSubcategory.selectSingleNode("@ObjID").nodeValue & "&ii="
Else
nodeSubcategory.selectSingleNode("@URL").nodeValue="Categories/RootCategories.asp?i=" & nodeSubcategory.selectSingleNode("@ObjID").nodeValue & "&ii=" & nodeSubcategory.selectSingleNode("@RootCategoryObjID").nodeValue
End If
node.appendChild nodeSubcategory
Set nodeSubcategory=Nothing
Next
Set nodesSubcategories=Nothing

Set xmlSubcategories=Nothing
End Sub
%>b. xml源文件
<?xml version="1.0" encoding="UTF-8"?>
<Root>
<SubCategory ObjID="" Name="" URL="">
<SubCategory ObjID="" Name="" URL="">
<SubCategory ObjID="" Name="" URL=""></SubCategory>
<SubCategory ObjID="" Name="" URL=""></SubCategory>
<SubCategory ObjID="" Name="" URL=""></SubCategory>
</SubCategory>
<SubCategory ObjID="" Name="" URL="">
</SubCategory>
</SubCategory>
<SubCategory ObjID="" Name="" URL="">
</SubCategory>
</Root>