• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

digester help

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

Dave
 
Betsy Camel
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic