开发者

I want to retrieve Map object using common digester

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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜