commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luke Shannon" <>
Subject Need a little help
Date Mon, 31 Jan 2005 23:45:17 GMT

I am using Digester to extract some XML information. I have run into
problems and need some help.

Here is my schema:

  <ITEM NAME="category" TYPE="text">Category 4</ITEM>
  <ITEM NAME="provider" TYPE="text">Provider</ITEM>
  <ITEM NAME="progress_ref" TYPE="text">11008</ITEM>
  <ITEM NAME="name" TYPE="text">Name</ITEM>
  <ITEM NAME="desc" TYPE="text">Description</ITEM>
  <ITEM NAME="poster" TYPE="text">Company Who Posted</ITEM>
  <ITEM NAME="sort" TYPE="text">8</ITEM>
  <ITEM DIR="x.ppt" HEIGHT="-1" NAME="kcfileupload" SIZE="9728" STYPE="file"
TYPE="upload" WIDTH="-1">x.ppt</ITEM>

The end result I would like to get is a TreeMap containing all the name
attributes as keys and the contents of the item tags as values from a
directory of XML files containing the above schema.

I get the follow error when I try and run my program:

Jan 31, 2005 6:24:18 PM org.apache.commons.digester.Digester endElement
SEVERE: End event threw exception
java.lang.NoSuchMethodException: No such accessible method: setContents() on
object: Item

This confuses me because the Item class does have this method.

Below I have pasted my code.

Here is the method that does the work:

public Version digest() throws IOException, SAXException {
  digester = new Digester();
  digester.addObjectCreate("DATA/VERSION", Version.class);
  digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
  digester.addSetProperties("DATA/VERSION/ITEM", "name", "name");
  digester.addCallMethod("DATA/VERSION/ITEM", "setContents");
  return (Version)digester.parse(parseMe);

Here is the Item class. The purpose of the class is to return a TreeMap for
each item tag.

public class Item {
 private String contents = new String();
 private String name = new String();

 public Item() { }
  * @param content The content to set.
 public void setName(String _name) {
     Trace.ENTER("Setting the name property to " + _name); = _name;

 public void setContents (String _contents) {
     this.contents = _contents;

 public TreeMap getValues () {
     TreeMap map = new TreeMap();
     map.put(name, contents);
     return map;

Here is the Version class, it is contains a TreeMap which holds the data for
all the item tags.

 * @author lshannon
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
public class Version {
    TreeMap fieldsValues;

 public Version() {
     fieldsValues = new TreeMap();

  * @return Returns the iTEMS.
 public TreeMap getMap() {
  return fieldsValues;
  * @param items The iTEMS to set.
 public void setITEMS(TreeMap map) {

I am not that experienced with Digester. What I have looks to me like it
should work, however maybe I am not understanding something. Is there any
easier way to obtain my goal?

Any help on this matter would be greatly appreciated.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message