I am trying to parse an XML file similar to the one shown below:
<products>
<product partNumber="1000">
...
</product>
<product partNumber="2000">
...
</product>
</products>
I want Digester to return a HashMap with partNumber as the key and
product as the value. How do I put the product on to the HashMap? I
guess I don't know how <call-param-rule> can specify the object from top
of the stack as a parameter. Here's my unsuccessful attempt at this:
<digester-rules>
<object-create-rule pattern="products" classname="java.util.HashMap"/>
<pattern value="products/product">
<object-create-rule classname="Product"/>
<set-properties-rule>
<alias attr-name="partNumber" prop-name="partNumber"/>
</set-properties-rule>
<call-method-rule methodname="put" paramcount="2"
paramTypes="java.lang.String,Product"/>
<call-param-rule paramnumber="0" attrname="partNumber"/>
<call-param-rule paramnumber="1"/> <--- what to do here?
</pattern>
</digester-rules>
Thanks.
Naresh Bhatia