commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Valerio Schiavoni <valerio.schiav...@gmail.com>
Subject Re: [digester] different xml, same objective ?
Date Wed, 28 Dec 2005 19:12:56 GMT
thanks for the suggestion, but still doesn't working, reporting:
Using studentXML1: Students List [Name=Java Boy & Course=JSP & Age=10]
Using studentXML2: Students List [Name=null & Course=null & Age=0]


2005/12/28, Diogo Quintela (EF) <diogo.quintela@ef.pt>:
>
> digester.addBeanPropertySetter
> ("students/student/property[@name='name']/@value", "name");
> digester.addBeanPropertySetter
> ("students/student/property[@name='course']/@value", "course");
> digester.addBeanPropertySetter
> ("students/student/property[@name='age']/@value", "age");
>
> If not, we may try to set property value to property named "value"



could you explain a bit more what do you mean by this ? the proposed
solution (apart from 'not working yet')  is some how too restrict, since it
requires to update the digester continuously when a new field on the student
object is created. the first approach leverages the developer to to do so,
and i was hoping to obtain the same result.


thanks,
valerio


-----------------------------------
> Diogo Bacelar Quintela
> EF - Tecnologias de Informação, Lda.
> Av. António Serpa, 26 - 4º Dto.
> 1050-027 Lisboa, Portugal
> Tel: (+351) 217 827 800
> Fax: (+351) 217 827 830
> Email: diogo.quintela@ef.pt
> PGP: 0xF51A5AB9
>
> > -----Original Message-----
> > From: Valerio Schiavoni [mailto:valerio.schiavoni@gmail.com]
> > Sent: quarta-feira, 28 de Dezembro de 2005 17:05
> > To: Jakarta Commons Users List
> > Subject: Re: [digester] different xml, same objective ?
> >
> > Hello Russel,
> > i did try using this code:
> > digester.addBeanPropertySetter
> > ("students/student/property[@name='name']/@value");
> >                 digester.addBeanPropertySetter
> > ("students/student/property[@name='course']/@value");
> >                 digester.addBeanPropertySetter
> > ("students/student/property[@name='age']/@value");
> >
> > (i think you forgot a '@' before the name), but it doesn't build the
> > Student
> > object properly.
> > this is the output i get:
> >
> > Using studentXML1: Students List [Name=Java Boy & Course=JSP & Age=10]
> > Using studentXML2: Students List [Name=null & Course=null & Age=0]
> >
> > where you can see that fields are not set properly.
> >
> >
> > 2005/12/28, Russell Simpkins <russellsimpkins@hotmail.com>:
> > >
> > > given
> > >
> > > >     protected String studentsXML2 = "<?xml version=\"1.0\"?>"
> > > >         + "<students>"
> > > >         + "<student>"
> > > >         + "<property name=\"name\" value=\"Java Boy\"/>"
> > > >         + "<property name=\"course\" value=\"Digester\"/>"
> > > >         + "<property name=\"age\" value=\"10\"/>"
> > > >         + "</student>"
> > > >         + "</students>";
> > > >
> > > >     public void testAddBeanPropertySetter1() {
> > > >
> > > >         DigestStudents ds = new DigestStudents(studentsXML1);
> > > >         ds.digest();
> > > >
> > > >     }
> > > >
> > > >     public void testAddBeanPropertySetter2() {
> > > >
> > > >         DigestStudents ds = new DigestStudents(studentsXML2);
> > > >         ds.digest();
> > > >
> > > >     }
> > > >
> > > >     private class DigestStudents {
> > > >         List<Student> students;
> > > >         String input;
> > > >         public DigestStudents(String input) {
> > > >
> > > >             students = new ArrayList<Student>();
> > > >             this.input = input;
> > > >         }
> > > >
> > > >         private void digest() {
> > > >             try {
> > > >                 Digester digester = new Digester();
> > > >                 digester.setRules(new ExtendedBaseRules());
> > > >
> > > >                 digester.push(this);
> > > >
> > > >                 digester.addObjectCreate("students/student",
> > > >Student.class);
> > > >
> > > >                 digester.addBeanPropertySetter
> ("students/student/?");
> > >
> > > did you try:
> > >
> > > digester.addBeanPropertySetter
> > > ("students/student/property[name='name']/@value");
> > > digester.addBeanPropertySetter
> > > ("students/student/property[name='course']/@value");
> > > digester.addBeanPropertySetter
> > > ("students/student/property[name='age']/@value");
> > >
> > > which is the XPath way to grab those property values
> > >
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> > >
> > >
> >
> >
> > --
> > To Iterate is Human, to Recurse, Divine
> > James O. Coplien, Bell Labs
>
>
>


--
To Iterate is Human, to Recurse, Divine
James O. Coplien, Bell Labs

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