Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

digester help

 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Could anyone please help me find the mistake!!!
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't forget to check here

Dave
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i couldnt find solutions to my problem in the link specified by you dave!!!
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic