[thelist] XML hierarchical menu
Chris Marsh
chris at webbtech.co.uk
Fri Sep 6 08:00:02 CDT 2002
Dear all
Specific questions are at the bottom of the post, after all
explanations.
I am producing an ASP class that generates a vertical navigation bar.
Some of the links have sub-sections, and sub-sub-sections. An example
would be:
<ul>
<li>
Link 1
</li>
<li>
Link 2
<ul>
<li>
Sub-link 1
</li>
</ul>
</li>
</ul>
I want to pull the information for the links from an XML document. An
example would be:
<?xml version="1.0" encoding="ISO-8859-1"?>
<wt:menu xmlns:wt="http://www.wt.co.uk">
<wt:item url="/wt/home.asp">
Home
</wt:item>
<wt:item url="/wt/news.asp">
News
</wt:item>
<wt:item url="/wt/expertise.asp">
Expertise
<wt:item url="/wt/expertise/consultancy.asp">
Consultancy
</wt:item>
</wt:item>
</wt:menu>
I figured that the way to go about formatting this XML into the menu
system would be something like this (pseudo-code):
Function FormatLink(Value)
Format into valid HTML
End Function
Function GetNextLevel(Root_Position)
Get collection of nodes 1 level down from Root_Position
For I = 0 To Len(collection of nodes)
GetNextLevel = GetNextLevel & FormatLink(node(i).Text)
If node(i) has child nodes
strSubLevel = GetNextLevel(node(i))
GetNextLevel = GetNextLevel & strSubLevel
End If
Next
End Function
Function CreateMenu()
Load XMLdoc
CreateMenu = GetNextLevel(Root_Position)
End Function
My questions are as follows:
1) Does this seem a logical way to go about creating what I want?
2) If the answer to (1) is "yes", does anyone know of an online class
reference giving me the methods etc. to achieve this? I have googled and
MS'd already, but haven't been able to locate an exhaustive reference.
Many thanks in advance
Chris Marsh
More information about the thelist
mailing list