This has got to be simple!
When I run the code below the parse sees each instance of person but nothing
is read from the xml file, why?
Here is the output:
SETAGE:0
SETNAME:
SETAGE:0
SETNAME:
SETAGE:0
SETNAME:
=0
=0
=0
here is my main routine:
public class SampleDigester
{
public static void main(String [] args) throws Exception
{
List people = new ArrayList();
// Configure Digester from XML ruleset
Digester digester = new Digester();
digester.addObjectCreate("people/person", Person.class);
digester.addSetNext("people/person", "add" ,"Person");
digester.addBeanPropertySetter("people/person", "name");
digester.addBeanPropertySetter("people/person", "age");
// Push empty List onto Digester's Stack
digester.push( people );
// Parse the XML document
InputStream input = new FileInputStream( "person.xml" );
digester.parse( input );
for (int i=0;i<people.size();i++)
{
Person p = (Person)people.get(i);
System.out.println(p.getName()+"="+p.getAge());
}
}
}
Here is my bean:
import java.io.Serializable;
public class Person implements Serializable
{
private String id;
private String name;
private int age;
public Person() {}
public String getId() { return id; }
public void setId(String v) {
System.out.println("SETID:"+v);
id = v;
}
public String getName() { return name; }
public void setName(String v) {
System.out.println("SETNAME:"+v);
name = v;
}
public int getAge() { return age; }
public void setAge(int v) {
System.out.println("SETAGE:"+v);
age = v;
}
}
Here is my xml:
<people>
<person>
<name>Tom Higgins</name>
<age>25</age>
</person>
<person>
<name>Barney Smith</name>
<age>75</age>
</person>
<person>
<name>Susan Shields</name>
<age>53</age>
</person>
</people>
--
View this message in context:
http://www.nabble.com/Someone-HELP%21%21%21%21--please-tf3362618.html#a9354613
Sent from the Commons - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]