我有一个xml如下。
<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>
我尝试使用digester将其作为Map对象检索。
我希望输出为:
作为地图对象的列表。
{CLAIM_TICKET_1={CLAIM_TICKET_Groups=Kalyan,Testing=Ram},
CLAIM_TICKET_2={CLAIM_TICKET_Groups=Raju,Testing=Varma}}
我的代码显示错误:
String Xpath =&#34; map / map&#34 ;;
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");
答案 0 :(得分:0)
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.