commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Russell Simpkins" <russellsimpk...@hotmail.com>
Subject RE: [digester] different xml, same objective ?
Date Wed, 28 Dec 2005 15:59:42 GMT
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


Mime
View raw message