I have a xml as below.
<list>
<map>
<map name="CLAIM_TICKET_1">
<val name="CLAIM_TICKET_Groups">Kalyan</val>
<val name="Testing">Ram</val>
</map>
<map name="CLAIM_TICKET_2">
<val name="CLAIM_TICKET_Groups">Raju</val>
<val name="Testing">Varma</val>
</map>
</list>
I trying to retrieve that as Map object using digester.
I want output as:
As list of Map objects.
{CLAIM_TICKET_1={CLAIM_TICKET_Groups=Kalyan,Testing=开发者_运维百科Ram},
CLAIM_TICKET_2={CLAIM_TICKET_Groups=Raju,Testing=Varma}}
My Code shows error:
String Xpath = "map/map";
digester.addObjectCreate(Xpath, HashMap.class);
digester.addCallMethod(Xpath , "put", 2);
digester.addCallParam(Xpath, 0, "name");
digester.addObjectCreate(Xpath, HashMap.class);
digester.addCallMethod(Xpath+"/val" , "put", 2);
digester.addCallParam(Xpath+"/val", 0, "name");
digester.addCallParam(Xpath+"/val", 1);
digester.addSetNext(Xpath+"/val", "put");
String Xpath = "map/map";
//For every occurence of list/map add map object to list object
digester.addObjectCreate("list/map", ArrayList.class);
digester.addObjectCreate(Xpath, HashMap.class);
digester.addCallMethod(Xpath+"/val" , "put", 2);
digester.addCallParam(Xpath+"/val", 0, "name");
digester.addCallParam(Xpath+"/val", 1);
digester.addSetNext("list/map", "add");
It works fine.
精彩评论