commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dmitriy Kuznetsov <>
Subject Re: Commons betwixt 0.8 - reading Map from XML
Date Fri, 05 Sep 2008 17:51:56 GMT

Simone Tripodi wrote:
> Hi Dmitriy,
> you don't you use just the commons-digester rules to map the xml to your
> map?
> It's also a betwixt dependency library, and maybe it could be easier.
> Best regards,
> Simone
Well, i've made some changes since first time. The XML now looks like

	<group name="...">
		<entry name="...">
		<entry name="...">
	<group name="...">
		<entry name="...">

And as Simone suggested, i've used commons Digester instead of Betwixt:

	Digester digester = new Digester();
	digester.addObjectCreate("metadata", Hashtable.class);
	digester.addObjectCreate("metadata/group", ListOrderedMap.class);
	Rule r = new CallMethodRule(1, "put", 2);
	digester.addRule("metadata/group", r);
	digester.addCallParam("metadata/group", 0, "name");
	digester.addCallParam("metadata/group", 1, true);
	// MetadataEntry is a simple bean that holds values of <entry/> section
	digester.addObjectCreate("metadata/group/entry", MetadataEntry.class);
	r = new SetNestedPropertiesRule();
	digester.addRule("metadata/group/entry", r);
	r = new CallMethodRule(1, "put", 2);
	digester.addRule("metadata/group/entry", r);
	digester.addCallParam("metadata/group/entry", 0, "name");
	digester.addCallParam("metadata/group/entry", 1, true);

	// a little later

	InputStream is =
	Object result = digester.parse(is);

And it works. The resulting data structure is: Map<String, Map<String,
Simone, thanks! =)
View this message in context:
Sent from the Commons - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message