A Dynamic Tree Menu System, Part 2By Sam Reynoso
ASP for HTML Code Generation
Introducing the Code
All the code necessary to generate the tree menu (except the XML) is stored in a single file called
menu.asp. At the top of the file we insert a basic style definition
to control the look of the text used in the menu items. We encapsulate our style into
a single class called
node which we apply later on. The style
definition is presented below:
Next, we load our XML file into the MSXML parser. We check for errors that can
occur along the way. The subroutine
sbShowXMLParseError() displays a detailed
explanation of the parse error, if it is encountered, and helps pinpoint the
exact location of the error.
Just before we begin drawing the tree menu, we give the developer an opportunity to specify what folders should be expanded by default. This is done by putting values into an array. When the menu is generated, the array is probed for elements that match the current node. If a match is found, the folder is displayed as expanded.
Now we make our first call to the subroutine that will actually generate the
HTML for our navigation tree. The parameter
iTotal is passed in by reference and
keeps track of the total number of elements in our tree. It will be used in the
until all nodes of the objDocument object have been visited.
in the number of elements used in the tree menu. A
For loop uses the value of
to iterate through a cycle equivalent to the number of nodes in the menu.
exactly matches the number of elements in the tree menu.
Now that we've examined the purpose and general code for
menu.asp from a very high-level perspective,
it's time that we drill into the guts of the page - the
DisplayNode() function. In
Part 3 we'll tackle this task. (Do note, though, at any time you
may view a live demo of the dynamic tree navigation.)