My question is close to this one: Digester: Extracting node name
Even with the answer, I can’t find out.
Here is my xml file (from smartgwt RestDataSource POST):
<data>
<isc_OID_14>
<attribute1>value1</attribute1>
<attribute2>value2</attribute2>
</isc_OID_14>
</data>
I would like to create, with Commons Digester, the following map :
{attribute1=value1, attribute2=value2}
I already have those lines:
digester = new Digester();
digester.addObjectCreate("data", HashMap.class);
// some "put" rules matching something like data/*
return digester.parse(myFile);
I do not know the list nor the name of tags in the <data><sourceId /></data>. isc_OID_14 or attribute1 can be named foobar or id or attribute335…
I think something like this is what you want:
Basically it uses
ExtendedBaseRulesfor the wildcard matching.There are 3 rules:
data,ObjectCreateaHashMapdata/?(direct child of data), map[ID]=name(make thisRulea no-op if not needed)*(everything else), mapname=textOn my machine, this prints:
API links
org.apache.commons.digesterorg.apache.commons.digester.Ruleorg.apache.commons.digester.ExtendedBaseRules