You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Jiang, Jane (NIH/NCI) [C]" <ji...@mail.nih.gov> on 2007/12/18 16:34:48 UTC
Question about xml rule for Digester
Hi,
I am working on parse an xml file using Digester. I got the basics by
reading the AddressBook example. However, I could not find an example
that refers to an upper level tag attribute in the rule.
I am trying to create an object that contains a hash map of collections.
I included my xml data file, java class and the xml rule file.
I'd appreciate any advice you might offer.
Jane
Here is what my xml data file is like
<progress-bar key="Draft">
<branch flag="Y">
<step>
<action>Creation</action>
<status>Completed</status>
</step>
<step>
<action>Submission</action>
<status>Completed</status>
</step>
<step>
<action>Approval</action>
<status>Pending</status>
</step>
</branch>
<branch flag="N">
<step>
<action>Creation</action>
<status>Completed</status>
</step>
<step>
<action>Submission</action>
<status>Completed</status>
</step>
<step>
<action>Completion</action>
<status>Pending</status>
</step>
</branch>
</progress-bar>
Here is what my ProgressBar.java
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class ProgressBar {
private String key;
private HashMap<String, List> branches = new HashMap<String,
List>();
public ProgressBar() {
}
public void addBranch(String flag, ProgressStep step) {
if (branches.get(flag) == null){
branches.put(flag, new ArrayList());
}
branches.get(flag).add(step);
}
public void setKey(String key) {
this.key = key;
}
public String getKey() {
return key;
}
}
My xml rule is defined as following, except I don't know what I should
use between the ???s.
<!DOCTYPE digester-rules
PUBLIC "-//Jakarta Apache //DTD digester-rules XML V1.0//EN"
"http://jakarta.apache.org/commons/digester/dtds/digester-rules.dtd">
<digester-rules>
<pattern value="progress-bar">
<set-properties-rule/>
<pattern value="branch">
<pattern value="step">
<object-create-rule
classname="gov.nih.nci.iscs.oracle.acr.config.progress.ProgressStep"/>
<set-nested-properties-rule/>
<set-top-rule methodname="addBranch" paramcount="2" />
<call-param-rule paramnumber='0' attrname=''????flag of the
branch???'/>
<call-param-rule paramnumber='1' attrname='????The ProgressStep
object???'/>
</pattern>
</pattern>
</pattern>
</digester-rules>