commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Naresh Bhatia" <NBha...@sapient.com>
Subject [Digester] How to specify a <call-param-rule> parameter from top-of-stack
Date Fri, 24 Jan 2003 05:44:07 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message