手机
当前位置:查字典教程网 >编程开发 >ASP教程 >Dom遍历XML的一个例子,结果为树状结构
Dom遍历XML的一个例子,结果为树状结构
摘要:knowledge.XML文件复制代码代码如下:什么是ASPcxx2001-02-20ASP:ActiveServerPage什么是ASPc...

knowledge.XML文件

复制代码 代码如下:<?xmlversion="1.0"encoding="gb2312"?>

<?xml:stylesheettype="text/xsl"href="knowledge.xsl"?>

<Ebaihename="Ebaihe"type="gs"id="gs000">

<知识管理name="知识管理"type="rt"id="rt000">

<目录name="vc++"type="ml"id="ml003"/>

<目录name="asp"type="ml"id="ml001">

<知识name="什么是ASP1"type="zs"id="zs001">

<title>什么是ASP</title>

<author>cxx</author>

<adddate>2001-02-20</adddate>

<content>ASP:ActiveServerPage</content>

</知识>

<知识name="什么是ASP2"type="zs"id="zs002">

<title>什么是ASP</title>

<author>cxx</author>

<adddate>2001-02-20</adddate>

<content>ASP:ActiveServerPage</content>

</知识>

</目录>

<目录name="vbs"type="ml"id="ml002">

<知识name="什么是vbs1"type="zs"id="zs003">

<title>什么是ASP</title>

<author>cxx</author>

<adddate>2001-02-20</adddate>

<content>ASP:ActiveServerPage</content>

</知识>

<知识name="什么是vbs2"type="zs"id="zs004">

<title>什么是ASP</title>

<author>cxx</author>

<adddate>2001-02-20</adddate>

<content>ASP:ActiveServerPage</content>

</知识>

</目录>

</知识管理>

<留言簿name="留言簿"type="ly"id="ly000">

<单元name="你好"type="dy"id="dy001">

<留言name="Whoareyou"type="zs"id="zs005">

<title>什么是ASP</title>

<author>cxx</author>

<adddate>2001-02-20</adddate>

<content>ASP:ActiveServerPage</content>

</留言>

<留言name="你好"type="zs"id="zs006">

<title>什么是ASP</title>

<author>cxx</author>

<adddate>2001-02-20</adddate>

<content>ASP:ActiveServerPage</content>

</留言>

</单元>

<单元name="我的留言"type="dy"id="dy003"/>

</留言簿>

<留言簿name="留言簿"type="ly"id="ly001"/>

</Ebaihe>

bianli.asp文件

复制代码 代码如下:<%@LANGUAGE=VBScript%>

<%

functiongetimgstr(ttid,ttname,ttlvl,tttype,ttlf,ttlstr)

dimttstr1

ifttlvl=0then

ttstr1=ttstr1&"<ahref="&chr(34)&"#"&chr(34)

ttstr1=ttstr1&"onclick="&chr(34)&"callOnClickDiv('"&ttid&"','"&"2"&"')"

ttstr1=ttstr1&chr(34)&">"

ttstr1=ttstr1&"<imgborder="&chr(34)&"0"&chr(34)&"src="&chr(34)

ttstr1=ttstr1&"image/Computer.gif"&chr(34)&"height=16>"&"</a>"

ttstr1=ttstr1&"<ahref="&chr(34)&"#"&chr(34)

ttstr1=ttstr1&"onclick="&chr(34)&"callOnClickDiv('"&ttid&"','"&"2"&"')"

ttstr1=ttstr1&chr(34)&">"

ttstr1=ttstr1&ttname&"</a><br>"&vbcrlf

ttstr1=ttstr1&"<divid="&chr(34)&ttid&chr(34)&"style=display:none>"&vbcrlf

else

fori=2tolen(ttlstr)-1

ifmid(ttlstr,i,1)="1"then

ttstr1=ttstr1&"<imgborder="&chr(34)&"0"&chr(34)&"src="&chr(34)

ttstr1=ttstr1&"image/I-line.gif"&chr(34)&"height=16>"

endif

ifmid(ttlstr,i,1)="0"then

ttstr1=ttstr1&"<imgborder="&chr(34)&"0"&chr(34)&"src="&chr(34)

ttstr1=ttstr1&"image/none.gif"&chr(34)&"height=16>"

endif

next

iftttype=1then

ttstr1=ttstr1&"<ahref="&chr(34)&"#"&chr(34)

ttstr1=ttstr1&"onclick="&chr(34)&"callOnClickDiv('"&ttid&"','"&ttlf&"')"

ttstr1=ttstr1&chr(34)&">"

ttstr1=ttstr1&"<imgborder="&chr(34)&"0"&chr(34)&"src="&chr(34)

ifttlf=0then

ttstr1=ttstr1&"image/T-plus.gif"&chr(34)&"id="&chr(34)&"l-"&ttid&chr(34)&"

height=16></a>"

else

ttstr1=ttstr1&"image/l-plus.gif"&chr(34)&"id="&chr(34)&"l-"&ttid&chr(34)&"

height=16></a>"

endif

ttstr1=ttstr1&"<ahref="&chr(34)&"#"&chr(34)

ttstr1=ttstr1&"onclick="&chr(34)&"callOnClickDiv('"&ttid&"','"&ttlf&"')"

ttstr1=ttstr1&chr(34)&">"

ttstr1=ttstr1&"<imgborder="&chr(34)&"0"&chr(34)&"src="&chr(34)

ttstr1=ttstr1&"image/c-fold.bmp"&chr(34)&"id="&chr(34)&"p-"&ttid&chr(34)&"

height=16></a>"

ttstr1=ttstr1&"<ahref="&chr(34)&"#"&chr(34)

ttstr1=ttstr1&"onclick="&chr(34)&"callOnClickDiv('"&ttid&"','"&ttlf&"')"

ttstr1=ttstr1&chr(34)&">"

ttstr1=ttstr1&ttname&"</a><br>"&vbcrlf

ttstr1=ttstr1&"<divid="&chr(34)&ttid&chr(34)&"style=display:none>"&vbcrlf

else

ttstr1=ttstr1&"<imgborder="&chr(34)&"0"&chr(34)&"src="&chr(34)

ifttlf=0then

ttstr1=ttstr1&"image/t-line.gif"&chr(34)&"height=16>"

else

ttstr1=ttstr1&"image/l-line.gif"&chr(34)&"height=16>"

endif

ttstr1=ttstr1&"<ahref="&chr(34)&"#"&chr(34)

ttstr1=ttstr1&"onclick="&chr(34)&"callOnClickDiv('"&ttid&"','3')"

ttstr1=ttstr1&chr(34)&">"

ttstr1=ttstr1&"<imgborder="&chr(34)&"0"&chr(34)&"src="&chr(34)

ttstr1=ttstr1&"image/leaf.bmp"&chr(34)&"id="&chr(34)&"p-"&ttid&chr(34)&"

height=16></a>"

ttstr1=ttstr1&"<ahref="&chr(34)&"#"&chr(34)

ttstr1=ttstr1&"onclick="&chr(34)&"callOnClickDiv('"&ttid&"','3')"

ttstr1=ttstr1&chr(34)&">"

ttstr1=ttstr1&ttname&"</a><br>"&vbcrlf

ttstr1=ttstr1&"<divid="&chr(34)&ttid&chr(34)&"style=display:none></div>"&vbcrlf

endif

endif

getimgstr=ttstr1

endfunction

FunctionShowNode(node,mylvl,myleaf,mylstr)

dimttstr

dimmystr

dimttleaf

dimttn

ttn=0

ifmyleaf=0then

ttleaf=0

else

ttleaf=1

endif

ForEachchildInnode.childNodes

ttn=ttn+1

If(child.nodeType=1)Then

nod_name=child.Attributes.getnamedItem("name").Text

nod_type=child.Attributes.getnamedItem("type").Text

nod_id=child.Attributes.getnamedItem("id").Text

ifnod_type<>"zs"then

If(child.hasChildNodes)Then

ifttn=node.childnodes.lengththen

mystr=mystr&getimgstr(nod_id,nod_name,mylvl,1,1,mylstr&"0")

ttstr=ShowNode(child,mylvl+1,1,mylstr&"0")

else

mystr=mystr&getimgstr(nod_id,nod_name,mylvl,1,0,mylstr&"1")

ttstr=ShowNode(child,mylvl+1,0,mylstr&"1")

endif

mystr=mystr&ttstr

mystr=mystr&"</div>"

else

ifttn=node.childnodes.lengththen

mystr=mystr&getimgstr(nod_id,nod_name,mylvl,0,1,mylstr&"0")

else

mystr=mystr&getimgstr(nod_id,nod_name,mylvl,0,0,mylstr&"1")

endif

EndIf

else

ifttn=node.childnodes.lengththen

mystr=mystr&getimgstr(nod_id,nod_name,mylvl,0,1,mylstr&"0")

else

mystr=mystr&getimgstr(nod_id,nod_name,mylvl,0,0,mylstr&"1")

endif

endif

endif

Next

ShowNode=mystr

EndFunction

dimxmldoc

dimxmlstr

Setxmldoc=Server.CreateObject("Microsoft.XMLDOM")

xmldoc.async=false

xmldoc.load(Server.MapPath("knowledge.xml"))

xmlstr=ShowNode(xmldoc,0,0,"")

'setxmldoc=nothing

'parent.results.display(source.transformNode(style));

%>

<html>

<head>

</head>

<body>

<scriptlanguage="VBScript">

dimolditem

subOnClickDiv(DivId,pType)

if(document.all(DivId).style.display="none")then

document.all(DivId).style.display=""

if(pType="0")then

document.all("l-"+DivId).src="image/t-minus.gif"

document.all("p-"+DivId).src="image/o-fold.bmp"

endif

if(pType="1")then

document.all("l-"+DivId).src="image/l-minus.gif"

document.all("p-"+DivId).src="image/o-fold.bmp"

endif

'if(pType="3")then

'document.all("p-"+DivId).src="image/o-fold.bmp"

'endif

else

document.all(DivId).style.display="none"

if(pType="0")then

document.all("l-"+DivId).src="image/t-plus.gif"

document.all("p-"+DivId).src="image/c-fold.bmp"

endif

if(pType="1")then

document.all("l-"+DivId).src="image/l-plus.gif"

document.all("p-"+DivId).src="image/c-fold.bmp"

endif

'if(pType="3")then

'document.all("p-"+DivId).src="image/c-fold.bmp"

'endif

endif

endsub

</script>

<fontname="宋体"size="2">

<nobr><%=xmlstr%></nobr></font>

</body>

【Dom遍历XML的一个例子,结果为树状结构】相关文章:

ASP中一个用VBScript写的随机数类

Asp中文件上传,fso方法大全

如何限制同一用户名同时登陆

ASP中一个字符串处理类

用XMLHTTP很好的一个例子

AspJpeg V1.5.0 破解版

ASP调用SQL SERVER存储程序

防范ASP木马的十大基本原则强列建议看下

一个简单的asp数据库操作类

关于Script的Defer属性 原创

精品推荐
分类导航