You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Luke Shannon <ls...@futurebrand.com> on 2005/02/01 00:45:17 UTC

Need a little help

Hi;

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

Here is my schema:

<VERSION>
  <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>
</VERSION>

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.setValidating(false);
  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);
  this.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) {
  fieldsValues.putAll(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.

Luke




---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Need a little help

Posted by Luke Shannon <ls...@futurebrand.com>.
Success! Thanks Wendy.

This is what worked, outside of a few small changes syntax changes, your
thinking is exactly correct.

public TreeMap digest() throws IOException, SAXException {
  digester = new Digester();
  digester.setValidating(false);
  digester.addObjectCreate("DATA/VERSION", TreeMap.class);
  digester.addCallMethod("DATA/VERSION/ITEM", "put", 2);
  digester.addCallParam("DATA/VERSION/ITEM", 0, "NAME");
  digester.addCallParam("DATA/VERSION/ITEM", 1);
  return (TreeMap)digester.parse(parseMe);

 }

Luke


----- Original Message ----- 
From: "Wendy Smoak" <ja...@wendysmoak.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Tuesday, February 01, 2005 3:19 PM
Subject: Re: Need a little help


> From: "Luke Shannon" <ls...@futurebrand.com>
>
> >  public TreeMap digest() throws IOException, SAXException {
> >   digester = new Digester();
> >   digester.setValidating(false);
> >   digester.addObjectCreate("DATA/VERSION", "createTreeMap");
>
> An ObjectCreateRule needs to know the type of object to create, not a
method
> to call.  You need to let Digester create an object and push it on the
> stack, and calling createTreeMap won't do that.
>
> >   digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name");
> >   digester.addCallMethod("DATA/VERSION/ITEM", "addItem", 0);
> >   return fieldsValues;
> >  }
>
> I thought...
>    digester = new Digester();
>    digester.setValidating(false);
>    digester.addObjectCreate("DATA/VERSION", "TreeMap.class");
>    digester.addCallMethod("DATA/VERSION/ITEM", "put", 2);
>    digester.addCallParam("DATA/VERSION/ITEM", 0, "NAME");
>    digester.addCallParam("DATA/VERSION/ITEM", 1);
>    return digester.parse(file);
>
> It should create a TreeMap and then call 'put' with the value of the NAME
> attribute and the body of the <ITEM> tag as the name/value pair.  Some of
> the method params may be switched around, double check the signatures.
>
> HTH,
> -- 
> Wendy Smoak
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Need a little help

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Luke Shannon" <ls...@futurebrand.com>

>  public TreeMap digest() throws IOException, SAXException {
>   digester = new Digester();
>   digester.setValidating(false);
>   digester.addObjectCreate("DATA/VERSION", "createTreeMap");

An ObjectCreateRule needs to know the type of object to create, not a method
to call.  You need to let Digester create an object and push it on the
stack, and calling createTreeMap won't do that.

>   digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name");
>   digester.addCallMethod("DATA/VERSION/ITEM", "addItem", 0);
>   return fieldsValues;
>  }

I thought...
   digester = new Digester();
   digester.setValidating(false);
   digester.addObjectCreate("DATA/VERSION", "TreeMap.class");
   digester.addCallMethod("DATA/VERSION/ITEM", "put", 2);
   digester.addCallParam("DATA/VERSION/ITEM", 0, "NAME");
   digester.addCallParam("DATA/VERSION/ITEM", 1);
   return digester.parse(file);

It should create a TreeMap and then call 'put' with the value of the NAME
attribute and the body of the <ITEM> tag as the name/value pair.  Some of
the method params may be switched around, double check the signatures.

HTH,
-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Need a little help

Posted by Luke Shannon <ls...@futurebrand.com>.
Hi Wendy;

Thanks for you help.

Is this along the lines of what you were thinking (see below)? All the
methods being called now are defined in the XMLParser class.

I am getting a NullPointerException right now, I am in the midst of
improving my debugging to determine where it is occuring.

Thanks,

Luke


import java.io.File;
import java.io.IOException;
import java.util.TreeMap;
import java.util.Vector;
//Digester imports
import org.apache.commons.digester.Digester;
import org.xml.sax.SAXException;


/**
 * @author lshannon
 * @since November 2004
 * The XMLParser takes a File object (must contain a xml file type).
 * This class is part used in the FutureBrand CMS system. It is generally
 * used in the XMLDocument class.
 */
public class XMLParser {

 private TreeMap fieldsValues;
 private Digester digester;
 private File parseMe;
 private String name;

 /**
  * This returns a reference to the XMLParser ready to extract
  * content from the File file.
  * @param file This file should reference an XML type file
  */
 public XMLParser(File file) {
  parseMe = file;
 }

 /**
  * This class returns a TreeMap containing the content found in
  * all the <item> nodes of the document (key= @NAME, value= node contents).
  * @return A  TreeMap containing a key/value pairing for each item node of
a default.xml document
    * @throws IOException
  * @throws SAXException
  */
 public TreeMap digest() throws IOException, SAXException {
  digester = new Digester();
  digester.setValidating(false);
  digester.addObjectCreate("DATA/VERSION", "createTreeMap");
  digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name");
  digester.addCallMethod("DATA/VERSION/ITEM", "addItem", 0);
  return fieldsValues;
 }

 public void createTreeMap() {
     fieldsValues = new TreeMap();
 }

 public void addItem(String value) {
     Trace.ENTER("Inserting " + getName() + " " + value + " in to the main
map");
     fieldsValues.put(getName(), value);
 }

 public void setName(String name) {
     this.name = name;
 }

 public String getName() {
     return name;
 }
}


----- Original Message ----- 
From: "Wendy Smoak" <ja...@wendysmoak.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Tuesday, February 01, 2005 2:32 PM
Subject: Re: Need a little help


> From: "Luke Shannon" <ls...@futurebrand.com>
> > I have done away with the Version.class and decided to build my
collection
> > of Item maps within the class that calls the digester methods (a full
> > description of my code can be seen below). My problem now is using the
> > addSetNext method to call a local method.
>
> Why is there a TreeMap inside Item?  It doesn't look [to me] like you need
> an Item class at all, you could create a TreeMap when you hit <VERSION>
and
> add key/value pairs directly to it when you see <ITEM> tags.
>
> You wrote:
> > > To review, the end result was to get a TreeMap containing all the name
> > > attributes as keys and the contents of the item tags as values from a
> > > directory of XML files
>
> -- 
> Wendy Smoak
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Need a little help

Posted by Wendy Smoak <ja...@wendysmoak.com>.
From: "Luke Shannon" <ls...@futurebrand.com>
> I have done away with the Version.class and decided to build my collection
> of Item maps within the class that calls the digester methods (a full
> description of my code can be seen below). My problem now is using the
> addSetNext method to call a local method.

Why is there a TreeMap inside Item?  It doesn't look [to me] like you need
an Item class at all, you could create a TreeMap when you hit <VERSION> and
add key/value pairs directly to it when you see <ITEM> tags.

You wrote:
> > To review, the end result was to get a TreeMap containing all the name
> > attributes as keys and the contents of the item tags as values from a
> > directory of XML files

-- 
Wendy Smoak


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Need a little help

Posted by Luke Shannon <ls...@futurebrand.com>.
Continuing with my issue I have simplified things.

I have done away with the Version.class and decided to build my collection
of Item maps within the class that calls the digester methods (a full
description of my code can be seen below). My problem now is using the
addSetNext method to call a local method.

public TreeMap digest() throws IOException, SAXException {
  digester = new Digester();
  digester.setValidating(false);
  digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
  digester.addSetProperties("DATA/VERSION/ITEM", "name", "name");
  digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0);
    //declaration for addItem directly below this in the same class
  digester.addSetNext("DATA/VERSION/ITEM", "addItem");
  return fieldsValues;
 }

 public void addItem(Item in) {
     Trace.ENTER("Inserting " + in.getValues().toString() + " in to the main
map");
     fieldsValues.putAll(in.getValues());
 }

The weird thing is addItem doesn't get called and there is no error
reguarding it either (I would have thought one of the two would happen).

Also the name property is not getting set either. I have tried:

digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name");
digester.addSetProperties("DATA/VERSION/ITEM", "Name", "name");
digester.addSetProperties("DATA/VERSION/ITEM", "name", "name");

Just doesn't get called. Not sure why.

Any advice would be appreciated.

Luke

Schema:

 <VERSION>
   <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>
 </VERSION>

Item Class:

import java.util.TreeMap;

/**
 * @author lshannon
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
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);
  this.name = name;
 }

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

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




----- Original Message ----- 
From: "Luke Shannon" <ls...@futurebrand.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>; "Kishore
Senji" <ks...@gmail.com>
Sent: Tuesday, February 01, 2005 10:58 AM
Subject: Re: Need a little help


> Thank you Kishore;
>
> Your suggestions make sense and work.
>
> Now that things are working a little better a flaw has occurred to me. And
I
> am not married to this approach in anyway. If someone sees less complex
way
> of achieving my goal please let me know.
>
> To review, the end result was to get 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 below schema.
>
> <VERSION>
>   <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>
> </VERSION>
>
> My plan was to have an Item class create a TreeMap for each item tag (key
=
> @NAME, value = contents of the tag).
>
> At the close of each Item tag the TreeMap would be added to a TreeMap in
the
> Version class, which by the time the parser reaches the closing version
tag
> would contain entries for each of the item tags (it would get called for
> each item tag).
>
> Here are the methods below:
>
> At the close of each item tag I need to call the method below in the
Version
> class. In the example above this method would be called 8 times resulting
in
> fieldsValues contain 8 key/value pairings.
>
>  /**
>   * @param items The iTEMS to set.
>   */
>  public void setItems(TreeMap map) {
>   fieldsValues.putAll(map);
>  }
> }
>
> This is the method in the Item class that supplies the argument for the
> setITEMS above. For each item class it would be called once.
>
> /**
>   * @return Returns the iTEMS.
>   */
>  public TreeMap getMap() {
>   return fieldsValues;
>
>  }
>
> Here is my parsing method. After set
> digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0); I need to
> call the setItems method in version with the getMap method of Item
providing
> the argument. I took a stab at it below, this doesn't even compile, but I
> hope it illustrates what I mean. How can I do this? Is there a better way?
>
> public Version digest() throws IOException, SAXException {
>   digester = new Digester();
>   digester.setValidating(false);
>   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", 0);
> //how can i call the method of the version class with the item pattern,
> using an item method for the arguement?
>   digester.addCallMethod("DATA/VERSION/ITEM", "Version.setItems",
"getMap");
>     return (Version)digester.parse(parseMe);
>  }
>
> Thanks,
>
> Luke
>
>
> ----- Original Message ----- 
> From: "Kishore Senji" <ks...@gmail.com>
> To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
> Sent: Monday, January 31, 2005 7:18 PM
> Subject: Re: Need a little help
>
>
> > >
> > > public Version digest() throws IOException, SAXException {
> > >  digester = new Digester();
> > >  digester.setValidating(false);
> > >  digester.addObjectCreate("DATA/VERSION", Version.class);
> > >  digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
> > >  digester.addSetProperties("DATA/VERSION/ITEM", "name", "name");
> >
> > The above line should be
> > digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name"); Since
> > the NAME attribute is in capitals, where as the "name" property on
> > Item is in small letters
> >
> > >  digester.addCallMethod("DATA/VERSION/ITEM", "setContents");
> >
> > Digester is not able to find setContents because the above tells
> > digester to look for a method called setContents which takes no
> > arguments. But the setContents on Item takes a String. Since you are
> > looking to get the body content and set it to the contents of the
> > Item, use
> >
> > digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0);
> >
> > You might also want to add the Item to the Version's map I believe.
> > Since I don't see that call here, I would add it here
> >
> > digester.addSetNext("DATA/VERSION/ITEM", "addItem");
> >
> > Where "addItem" method will live on the Version class which takes an
> > Item as an argument and add it to the TreeMap with the "name" of the
> > "Item" as the key
> >
> > >  return (Version)digester.parse(parseMe);
> > > }
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Need a little help

Posted by Luke Shannon <ls...@futurebrand.com>.
Thank you Kishore;

Your suggestions make sense and work.

Now that things are working a little better a flaw has occurred to me. And I
am not married to this approach in anyway. If someone sees less complex way
of achieving my goal please let me know.

To review, the end result was to get 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 below schema.

<VERSION>
  <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>
</VERSION>

My plan was to have an Item class create a TreeMap for each item tag (key =
@NAME, value = contents of the tag).

At the close of each Item tag the TreeMap would be added to a TreeMap in the
Version class, which by the time the parser reaches the closing version tag
would contain entries for each of the item tags (it would get called for
each item tag).

Here are the methods below:

At the close of each item tag I need to call the method below in the Version
class. In the example above this method would be called 8 times resulting in
fieldsValues contain 8 key/value pairings.

 /**
  * @param items The iTEMS to set.
  */
 public void setItems(TreeMap map) {
  fieldsValues.putAll(map);
 }
}

This is the method in the Item class that supplies the argument for the
setITEMS above. For each item class it would be called once.

/**
  * @return Returns the iTEMS.
  */
 public TreeMap getMap() {
  return fieldsValues;

 }

Here is my parsing method. After set
digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0); I need to
call the setItems method in version with the getMap method of Item providing
the argument. I took a stab at it below, this doesn't even compile, but I
hope it illustrates what I mean. How can I do this? Is there a better way?

public Version digest() throws IOException, SAXException {
  digester = new Digester();
  digester.setValidating(false);
  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", 0);
//how can i call the method of the version class with the item pattern,
using an item method for the arguement?
  digester.addCallMethod("DATA/VERSION/ITEM", "Version.setItems", "getMap");
    return (Version)digester.parse(parseMe);
 }

Thanks,

Luke


----- Original Message ----- 
From: "Kishore Senji" <ks...@gmail.com>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Monday, January 31, 2005 7:18 PM
Subject: Re: Need a little help


> >
> > public Version digest() throws IOException, SAXException {
> >  digester = new Digester();
> >  digester.setValidating(false);
> >  digester.addObjectCreate("DATA/VERSION", Version.class);
> >  digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
> >  digester.addSetProperties("DATA/VERSION/ITEM", "name", "name");
>
> The above line should be
> digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name"); Since
> the NAME attribute is in capitals, where as the "name" property on
> Item is in small letters
>
> >  digester.addCallMethod("DATA/VERSION/ITEM", "setContents");
>
> Digester is not able to find setContents because the above tells
> digester to look for a method called setContents which takes no
> arguments. But the setContents on Item takes a String. Since you are
> looking to get the body content and set it to the contents of the
> Item, use
>
> digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0);
>
> You might also want to add the Item to the Version's map I believe.
> Since I don't see that call here, I would add it here
>
> digester.addSetNext("DATA/VERSION/ITEM", "addItem");
>
> Where "addItem" method will live on the Version class which takes an
> Item as an argument and add it to the TreeMap with the "name" of the
> "Item" as the key
>
> >  return (Version)digester.parse(parseMe);
> > }
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Need a little help

Posted by Kishore Senji <ks...@gmail.com>.
> 
> public Version digest() throws IOException, SAXException {
>  digester = new Digester();
>  digester.setValidating(false);
>  digester.addObjectCreate("DATA/VERSION", Version.class);
>  digester.addObjectCreate("DATA/VERSION/ITEM", Item.class);
>  digester.addSetProperties("DATA/VERSION/ITEM", "name", "name");

The above line should be 
digester.addSetProperties("DATA/VERSION/ITEM", "NAME", "name"); Since
the NAME attribute is in capitals, where as the "name" property on
Item is in small letters

>  digester.addCallMethod("DATA/VERSION/ITEM", "setContents");

Digester is not able to find setContents because the above tells
digester to look for a method called setContents which takes no
arguments. But the setContents on Item takes a String. Since you are
looking to get the body content and set it to the contents of the
Item, use

digester.addCallMethod("DATA/VERSION/ITEM", "setContents", 0);

You might also want to add the Item to the Version's map I believe.
Since I don't see that call here, I would add it here

digester.addSetNext("DATA/VERSION/ITEM", "addItem");

Where "addItem" method will live on the Version class which takes an
Item as an argument and add it to the TreeMap with the "name" of the
"Item" as the key

>  return (Version)digester.parse(parseMe);
> }
>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org