By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

Using Jakarta Digester with unlimited nested elements - how?

P: n/a
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.EmailOptionsActi on</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.

Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.