views:

39

answers:

1

Hi,

I've seen different threads that discuss the kind of issue I have. Here are few: http://www.mailinglistarchive.com/[email protected]/msg05061.html, http://stackoverflow.com/questions/2165168/digester-extracting-node-name).

Yet, I still can't find a solution to this issue. Here is my XML data:

<rows>
   <row>
        <firstname>Paul</firstname>
        <lastname>Moris</lastname>
   </row>
   <row>
        <firstname>John</firstname>
        <lastname>Aiyer</lastname>
        <age>35</age>
   </row>
</rows>

What I want is define XML rules that would allow me to map each row into a map. I can't map the elements by referring to their names because not all possible elements are known upfront.

I was hoping that something like this would allow me to do this:

<digester-rules>
     <pattern value="rows/row">
         <object-create-rule classname="Address"/>
         <set-next-rule methodname="add" paramtype="java.lang.Object"/>
         <set-properties-rule/>

         <pattern value="*">
             <call-method-rule methodname="set" paramcount="2"/>  
             <call-param-rule paramnumber='0'/>
             <call-param-rule paramnumber='1'/>
         </pattern>
     </pattern>
</digester-rules>

the implementation of Address is:

public class Address {
   Map<String,String> c= new HashMap<String,String>();

   public void set(String name, String value){
   c.put(name, value);
   }

  public String toString(){
   return c.toString();
  }
}

Unfortunately, when I run this code I get two addresses that are created but with empty underlying map. When I use ExtendedBaseRules, nothing is even matched.

Any help would be much appreciated.

Max.