Using Jakarta Digester with unlimited nested elements - how?

From: Gary Smart (gary_smart_at_acslink.net.au)
Date: 12/22/03


Date: Mon, 22 Dec 2003 00:09:10 GMT

Hello.

I've been searching news groups and apache and google, but can't solve
this one:

I have an XML file used to create menu items in a Swing UI. I have a
<menu> element that can have an unlimited number of other <menu>
elements. So for a menu structure like Tools|Options|Email, the XML
would be similar to:

<desktop>
   <menus>
     <menu> <-- Top Level Menu to be installed on a JMenuBar
       <name>Tools</name>
         <menu> <-- Sub Menu installed under "Tools"
            <name>Options</name>
             <action>au.com.smarttours.actions.EmailOptionsAction</action>
         </menu>
     <menu>
   </menus>
</desktop>

The <action> becomes the "Email" menu item.

I've been trying to use Jakarta Commons Digestor to parse the XML, but
cannot get it to successfully capture the nested <menu> elements. I've
tried the following with no success (d is a Digester instance):

         d.addObjectCreate("desktop/menus/*/menu", MenuInstaller.class);
         d.addCallMethod("desktop/menus/*/menu/name", "setMenuName", 0);
         d.addCallMethod("desktop/menus/*/menu/before", "addBefore", 0);
         d.addCallMethod("desktop/menus/*/menu/after", "addAfter", 0);

I thought this would work, but Digester logs "No rules found matching
'desktop/menus/menu'"

Other tried variations include:
    desktop/menus/menu (This only captures the first menu (Tools), as I
expected)

   desktop/menus/*menu
   */menu (getting dsperate!)
   *menu (getting desperate!)

The project has been using Digester for other (non-unlimited-nesting)
xml parsing successfully, so I'm trying to continue using it before
having to switch to JDOM or JAXP or something else. I reasonably suspect
that Digestor should be able to handle this?

Any help or suggestions would be greatly appreciated.

Thanks,
Gary.



Relevant Pages

  • Digester and illegal characters
    ... I'm using digester to parse a dynamically generated xml document. ... The problem is that some text content contains some *illegal* characters ... An interface needs to be provided for all of the objects generated so as ...
    (comp.lang.java.programmer)
  • Read xml with apache digester
    ... digester to read a xml. ... that the header ... I can read the XML, if I remove the colon at dcx:header. ...
    (comp.lang.java.programmer)
  • Re: Simple Java/XML question
    ... >I have the following XML file... ... If this is not a class project in which you are required to write the code ... consider using Digester ... Prev by Date: ...
    (comp.lang.java.programmer)
  • Apache Digester parse xml with ${var} to get environment var
    ... I want to use digester to parse an xml, then use it as a key to us ...
    (comp.lang.java.programmer)
  • Re: Need recommendations on technology/architecture
    ... based using JSPs, Java Servlets, XML, XSLT and regular Java classes to ... XML is no ... render the GUI. ... could access the same application without having to install a SWING ...
    (comp.lang.java)