jQuery in Action, 2nd edition*
The moose likes XML and Related Technologies and the fly likes digester help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "digester help" Watch "digester help" New topic
Author

digester help

Betsy Camel
Ranch Hand

Joined: Oct 02, 2003
Posts: 119
hi

I was trying to use digester for a xml with the following structure -

<Library>
<Book>

<author>thas</author>
<author>james</author>
<author>john</author>
</Book>
<Magazine>
<author>george</author>
</Magazine>
</Library>

the value when outputed

Value response=(Value)digester.parse("abc.xml");

response.toString(); displays only the last value in author book that is john.
May i know why and how this can be solved without changing the xml structure or the element names in the xml .
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by Betsy Camel:
hi

I was trying to use digester for a xml with the following structure -

<Library>
<Book>

<author>thas</author>
<author>james</author>
<author>john</author>
</Book>
<Magazine>
<author>george</author>
</Magazine>
</Library>

the value when outputed

Value response=(Value)digester.parse("abc.xml");

response.toString(); displays only the last value in author book that is john.
May i know why and how this can be solved without changing the xml structure or the element names in the xml .


your book should have a list to store the author and you have to put additional iteratir logic using digested rules to make it work.Can you post the diester rule that you are using for this parsing.


Rahul Bhattacharjee
LinkedIn - Blog
Betsy Camel
Ranch Hand

Joined: Oct 02, 2003
Posts: 119
import org.apache.commons.digester.*;

import java.io.*;
import java.util.*;

public class DigesterDriver {

public static void main( String[] args ) {

try {
Digester digester = new Digester();
digester.setValidating( false );

digester.addObjectCreate( "Cat", Cat.class );

digester.addObjectCreate( "Cat/book", Book.class );
digester.addBeanPropertySetter( "Cat/book/author", "author1" );
digester.addSetNext( "Cat/book", "addBook" );




File input = new File( "input.xml" );
Cat c = (Cat)digester.parse( input );

System.out.println( c.toString() );

} catch( Exception exc ) {
exc.printStackTrace();
}
}
}


Can you please tell me why the output is not displaying all the author names.

If there is a mistake in the way i have given the rule, please let me know how to do that too
Betsy Camel
Ranch Hand

Joined: Oct 02, 2003
Posts: 119
Hi
Could anyone please help me find the mistake!!!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Don't forget to check here

Dave
Betsy Camel
Ranch Hand

Joined: Oct 02, 2003
Posts: 119
i couldnt find solutions to my problem in the link specified by you dave!!!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You didn't notice that you won a book and we'll send it to you if you follow the instructions posted there? It doesn't solve your problem but hopefully makes you feel a little better.
vinay kumar
Ranch Hand

Joined: Sep 23, 2006
Posts: 31
Congrats Betsy for finding a solution and winning a book aswell.

Hey i would like to extend this thread to know something about you asked. Could you please tell me in breif what does digester mean. What it is used for ..

Cheers
vnay.
 
GeeCON Prague 2014
 
subject: digester help