An example of Dom traversal in XML with a tree structure

Source: Internet
Author: User
Tags xsl what is asp

Knowledge. XML file Copy codeThe Code is as follows: <? Xml version = "1.0" encoding = "gb2312"?>
<? Xml: stylesheet type = "text/xsl" href = "knowledge. xsl"?>
<Ebaihe name = "Ebaihe" type = "gs" id = "gs000">
<Knowledge Management name = "Knowledge Management" type = "rt" id = "rt000">
<Directory name = "vc ++" type = "ml" id = "ml003"/>
<Directory name = "asp" type = "ml" id = "ml001">
<Knowledge name = "What is ASP 1" type = "zs" id = "zs001">
<Title> what is ASP </title>
<Author> cxx </author>
<Adddate> 2001-02-20 </adddate>
<Content> ASP: Active Server Page </content>
</Knowledge>
<Knowledge name = "What is ASP 2" type = "zs" id = "zs002">
<Title> what is ASP </title>
<Author> cxx </author>
<Adddate> 2001-02-20 </adddate>
<Content> ASP: Active Server Page </content>
</Knowledge>
</Directory>
<Directory name = "vbs" type = "ml" id = "ml002">
<Knowledge name = "What Is vbs 1" type = "zs" id = "zs003">
<Title> what is ASP </title>
<Author> cxx </author>
<Adddate> 2001-02-20 </adddate>
<Content> ASP: Active Server Page </content>
</Knowledge>
<Knowledge name = "What Is vbs 2" type = "zs" id = "zs004">
<Title> what is ASP </title>
<Author> cxx </author>
<Adddate> 2001-02-20 </adddate>
<Content> ASP: Active Server Page </content>
</Knowledge>
</Directory>
</Knowledge management>
<Guestbook name = "Guestbook" type = "ly" id = "ly000">
<Unit name = "hello" type = "dy" id = "dy001">
<Message name = "Who are you" type = "zs" id = "zs005">
<Title> what is ASP </title>
<Author> cxx </author>
<Adddate> 2001-02-20 </adddate>
<Content> ASP: Active Server Page </content>
</Leave a message>
<Message name = "hello" type = "zs" id = "zs006">
<Title> what is ASP </title>
<Author> cxx </author>
<Adddate> 2001-02-20 </adddate>
<Content> ASP: Active Server Page </content>
</Leave a message>
</Unit>
<Unit name = "My message" type = "dy" id = "dy003"/>
</Guestbook>
<Guestbook name = "Guestbook" type = "ly" id = "ly001"/>
</Ebaihe>

Bianli. asp file
Copy codeThe Code is as follows: <% @ LANGUAGE = VBScript %>
<%
Function getimgstr (ttid, ttname, ttlvl, tttype, ttlf, ttlstr)
Dim ttstr1
If ttlvl = 0 then
Ttstr1 = ttstr1 & "<a href =" & chr (34) & "#" & chr (34)
Ttstr1 = ttstr1 & "onclick =" & chr (34) & "call OnClickDiv ('" & ttid & "', '" & "2 "&"')"
Ttstr1 = ttstr1 & chr (34) & ">"
Ttstr1 = ttstr1 & "Ttstr1 = ttstr1 & "image/Computer.gif" & chr (34) & "height = 16>" & "</a>"
Ttstr1 = ttstr1 & "<a href =" & chr (34) & "#" & chr (34)
Ttstr1 = ttstr1 & "onclick =" & chr (34) & "call OnClickDiv ('" & ttid & "', '" & "2 "&"')"
Ttstr1 = ttstr1 & chr (34) & ">"
Ttstr1 = ttstr1 & ttname & "</a> <br>" & vbcrlf
Ttstr1 = ttstr1 & "<div id =" & chr (34) & ttid & chr (34) & "style = display: none>" & vbcrlf
Else
For I = 2 to len (ttlstr)-1
If mid (ttlstr, I, 1) = "1" then
Ttstr1 = ttstr1 & "Ttstr1 = ttstr1 & "image/I-line.gif" & chr (34) & "height = 16>"
End if
If mid (ttlstr, I, 1) = "0" then
Ttstr1 = ttstr1 & "Ttstr1 = ttstr1 & "image/none.gif" & chr (34) & "height = 16>"
End if
Next
If tttype = 1 then
Ttstr1 = ttstr1 & "<a href =" & chr (34) & "#" & chr (34)
Ttstr1 = ttstr1 & "onclick =" & chr (34) & "call OnClickDiv ('" & ttid & "', '" & ttlf &"')"
Ttstr1 = ttstr1 & chr (34) & ">"
Ttstr1 = ttstr1 & "If ttlf = 0 then
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>"
End if
Ttstr1 = ttstr1 & "<a href =" & chr (34) & "#" & chr (34)
Ttstr1 = ttstr1 & "onclick =" & chr (34) & "call OnClickDiv ('" & ttid & "', '" & ttlf &"')"
Ttstr1 = ttstr1 & chr (34) & ">"
Ttstr1 = ttstr1 & "Ttstr1 = ttstr1 & "image/c-fold.bmp" & chr (34) & "id =" & chr (34) & "p-" & ttid & chr (34 )&"
Height = 16> </a>"
Ttstr1 = ttstr1 & "<a href =" & chr (34) & "#" & chr (34)
Ttstr1 = ttstr1 & "onclick =" & chr (34) & "call OnClickDiv ('" & ttid & "', '" & ttlf &"')"
Ttstr1 = ttstr1 & chr (34) & ">"
Ttstr1 = ttstr1 & ttname & "</a> <br>" & vbcrlf
Ttstr1 = ttstr1 & "<div id =" & chr (34) & ttid & chr (34) & "style = display: none>" & vbcrlf
Else
Ttstr1 = ttstr1 & "If ttlf = 0 then
Ttstr1 = ttstr1 & "image/t-line.gif" & chr (34) & "height = 16>"
Else
Ttstr1 = ttstr1 & "image/l-line.gif" & chr (34) & "height = 16>"
End if
Ttstr1 = ttstr1 & "<a href =" & chr (34) & "#" & chr (34)
Ttstr1 = ttstr1 & "onclick =" & chr (34) & "call OnClickDiv ('" & ttid & "', '3 ')"
Ttstr1 = ttstr1 & chr (34) & ">"
Ttstr1 = ttstr1 & "Ttstr1 = ttstr1 & "image/leaf.bmp" & chr (34) & "id =" & chr (34) & "p-" & ttid & chr (34 )&"
Height = 16> </a>"
Ttstr1 = ttstr1 & "<a href =" & chr (34) & "#" & chr (34)
Ttstr1 = ttstr1 & "onclick =" & chr (34) & "call OnClickDiv ('" & ttid & "', '3 ')"
Ttstr1 = ttstr1 & chr (34) & ">"
Ttstr1 = ttstr1 & ttname & "</a> <br>" & vbcrlf
Ttstr1 = ttstr1 & "<div id =" & chr (34) & ttid & chr (34) & "style = display: none> </div>" & vbcrlf
End if
End if
Getimgstr = ttstr1
End function
Function ShowNode (node, mylvl, myleaf, mylstr)
Dim ttstr
Dim mystr
Dim ttleaf
Dim ttn
Ttn = 0
If myleaf = 0 then
Ttleaf = 0
Else
Ttleaf = 1
End if
For Each child In node. 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
If nod_type <> "zs" then
If (child. hasChildNodes) Then
If ttn = node. childnodes. length then
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 ")
End if
Mystr = mystr & ttstr
Mystr = mystr & "</div>"
Else
If ttn = node. childnodes. length then
Mystr = mystr & getimgstr (nod_id, nod_name, mylvl, 0, 1, mylstr & "0 ")
Else
Mystr = mystr & getimgstr (nod_id, nod_name, mylvl, 0, mylstr & "1 ")
End if
End If
Else
If ttn = node. childnodes. length then
Mystr = mystr & getimgstr (nod_id, nod_name, mylvl, 0, 1, mylstr & "0 ")
Else
Mystr = mystr & getimgstr (nod_id, nod_name, mylvl, 0, mylstr & "1 ")
End if
End if
End if
Next
ShowNode = mystr
End Function
Dim xmldoc
Dim xmlstr
Set xmldoc = Server. CreateObject ("Microsoft. XMLDOM ")
Xmldoc. async = false
Xmldoc. load (Server. MapPath ("knowledge. xml "))
Xmlstr = ShowNode (xmldoc, 0, 0 ,"")
'Set xmldoc = nothing
'Parent. results. display (source. transformNode (style ));
%>
<Html>

<Head>
</Head>

<Body>
<Script language = "VBScript">

Dim olditem

Sub OnClickDiv (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"
End if
If (pType = "1") then
Document. all ("l-" + DivId). src = "image/l-minus.gif"
Document. all ("p-" + DivId). src = "image/o-fold.bmp"
End if
'If (pType = "3") then
'Document. all ("p-" + DivId). src = "image/o-fold.bmp"
'End if
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"
End if
If (pType = "1") then
Document. all ("l-" + DivId). src = "image/l-plus.gif"
Document. all ("p-" + DivId). src = "image/c-fold.bmp"
End if
'If (pType = "3") then
'Document. all ("p-" + DivId). src = "image/c-fold.bmp"
'End if
End if
End sub
</Script>
<Font name = "" size = "2">
<Nobr> <% = xmlstr %> </nobr> </font>
</Body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.