Listing B
// declare the variables that we need to use while processing the XML file.
var e;
varnodeid;
varparentid;
varlabelTxt;
varlinkTxt;
 
for (vari=0;i<menuItems.length;i++)
{
    // assign each element of the XML file to a variable
    e=menuItems[i];
   nodeid= 'm' + e.getElementsByTagName("node")[0].firstChild.data;
   parentid= 'm' + e.getElementsByTagName("parent")[0].firstChild.data;
   labelTxt=e.getElementsByTagName("label")[0].firstChild.data;
   linkTxt =e.getElementsByTagName("link")[0].firstChild.data;
 
    // oM.makeMenu('<id>','<parent id>','<label>','<url>')
 
    //is this a top level menu item ?
    if (parentid=="m0")
    {
       oM.makeMenu(nodeid,'',labelTxt,linkTxt);
    }
    else
    {
       oM.makeMenu(nodeid,parentid,labelTxt,linkTxt);
    }
}