Click for a special Ad Club offer

Building XML Bars, Beta.

Sorry! This will only work in IE5...

XML Menu bar as IE 5 DHTML behavior.

We will demonstrate how XML can leverage otherwise complicated WEB projects, we will implement a generic reusable menu bar in JavaScript and XML.

Please send us your feedback!

Scenario

As soon as I formulated the problem using XML as a data source for menu bars came in obvious.

In this tutorial we will implement XML Bar in

Every sample XML Bar in this tutorial has a help menu from which you can view components of this project

XML behind XML Bars

XML Bar is implemented in three layers:

The core functionality of the bar is buried inside the DHTML behavior JavaScript code and exposed to the HTML page through its methods, properties and events.

XMLBar menus hierarchy along with menu stylesheets, description and image are stored in XML. XML is parsed and cashed into DOM by MSXML parser inside the behavior scriplet. Submenus are rendered only when parent menu is activated.

XML also stores the action to fire on a menu click event. Action can be a Link to a web page or a chunk of JavaScript code. It can also be a Sub-Action. In the later case child menu inherits parent's action.

Action can be parameterized.

For example in the following fragment

<MENU>
<DESC>XML-DEV Archive </DESC>
<LINK> http://www.lists.ic.ac.uk/hypermail/xml-dev/ /index.html </LINK>
<SUBMENU>
<DESC>1999 </DESC>
<SUBACTION>
<SUB name="year" >99 </SUB>
</SUBACTION>
<SUBMENU>
<DESC>January </DESC>
<SUBACTION>
<SUB name="month" >01 </SUB>
</SUBACTION>
</SUBMENU>
<SUBMENU>
<DESC>February </DESC>
<SUBACTION>
<SUB name="month" >02 </SUB>
</SUBACTION>
</SUBMENU>
</SUBMENU>
</MENU>

XML-DEV Archive has two parameters: year and month .

The PAR elements will be substituted with content of corresponding SUB elements.

So when clicked two leaf submenus will have links:

Notice that the 12 months fragment can be reused someplace else. For example, to browse MIND archives the top Link element should be:

<LINK> http://www.microsoft.com/mind/
<PAR/>
<PAR/>
/inthisissue
<PAR/>
<PAR/>
.htm </LINK>

And for WebTechniques archives:

<LINK> http://www.webtechniques.com/toc/
<PAR/>
<PAR/>
toc.shtml </LINK>

Browse throw Archives menu of the sample bar to test it.

Wouldn't it be great to allow for reusable submenu groups? A group of 12 SUBMENU - months is an example of a fragment that can be used for most of magazines and monthly publications. 12 months for X years for Y publications ... Isn't it to much to type, to transfer, to parse?... To optimize XML Bar let's create XML file that will serve as a data source for reusable submenu groups. We will define url of the reusable groups collection through MGREF child of the BAR root. rgsn attribute stands for "reusable groups source name".

<BAR orientation="h" xmlns="x-schema :xbar_schema.xml" >
<MGREF rgsn="seasons" > http://www.cogx.com/xmlbar/ref-menu.xml </MGREF>
<MENU>
<DESCR>xml-dev archive </DESCR>
<LINK> http://www.lists.ic.ac.uk/hypermail/xml-dev/ /index.html </LINK>
<IMG>btfly.gif </IMG>
<SUBMENU>
<DESCR>1999 </DESCR>
<SUBACTION>
<SUB name="year" >99 </SUB>
</SUBACTION>
<SUBMENUGROUP rgsn="seasons" ref="12months" select="[@name = "mm" $and$ text() $le$ "03"]" >ff </SUBMENUGROUP>
</SUBMENU>
<SUBMENU>
<DESCR>1998 </DESCR>
<SUBACTION>
<SUB name="year" >98 </SUB>
</SUBACTION>
<SUBMENU> </SUBMENU>
</SUBMENU>
</MENU>
<more.../>
</BAR>

Future versions of XML Bar will allow more then one rgsn . For example, one can be for accounting reports and tax schedules, another for magazine publications. Submenu groups from both rgsn can be referred if needed.

The last optional attribute of SUBMENUGROUP element is XQL query string. It selects only months January through March of the current year. This filter is not hard to implement because DOM selectNodes and selectSingleNode methods support XSL XSL pattern-matching syntax. In fact the complete XQL query string is

It selects only months January through March of the current year. It is equivalent to cogx:select="mm<=3", but in the later case I would have to compile this pattern internally to XSL or XQL syntax.

XMLBar Properties, Methods and Events

XMLBar Properties, Methods and Events

JavaScript Xplained

Coming soon...

Please send us your feedback!
© Copyright 1998-1999 Cogitech Inc.