Thanks Jay, for your help. Your code and rules really got me enough to get going and resolve my issue.
Best Regards, RJ. -----Original Message----- From: Jay Khimani [mailto:[email protected]] Sent: Saturday, March 14, 2009 2:44 AM To: Commons Users List Subject: Re: How to map the following xml uisng digester Hi Rashid, Below is ur digester rules def... <digester-rules> <pattern value="eSummaryResult/DocSum"> <object-create-rule classname="digesterexample.DocumentSummary" /> <bean-property-setter-rule pattern="Id" propertyname="id"/> <pattern value="Item"> <object-create-rule classname="digesterexample.Item"/> <set-properties-rule> <alias attr-name="Name" prop-name="name" /> <alias attr-name="Type" prop-name="type" /> </set-properties-rule> <call-method-rule methodname="setValue" paramcount="0"/> <set-next-rule methodname="addItem"/> </pattern> </pattern> </digester-rules> Below is your DocumentSummary class.... public class DocumentSummary implements Serializable { private static final long serialVersionUID = 3147951652544001256L ; private long id = 0 ; private List listitems = null ; public DocumentSummary() { listitems = new ArrayList() ; } public long getId() { return id ; } public void setId( long id ) { this.id = id ; } public List getListitems() { return listitems ; } public void setListitems( List listitems ) { this.listitems = listitems ; } public void addItem( Item item ) { this.listitems.add( item ) ; } public String toString() { final String COMMA = ", " ; final StringBuffer buffy = new StringBuffer() ; buffy.append( "DocumentSummary ( " ).append( super.toString() ).append( COMMA ).append( "id = " ).append( this.id ).append( COMMA ) .append( "listitems = " ).append( this.listitems ).append( COMMA ).append( " )" ) ; return buffy.toString() ; } } Below is Item class public class Item implements Serializable { private static final long serialVersionUID = -8318635625838928564L ; private String name ; private String type ; private String value ; public String getName() { return name ; } public void setName( String name ) { this.name = name ; } public String getType() { return type ; } public void setType( String type ) { this.type = type ; } public String getValue() { return value ; } public void setValue( String value ) { this.value = value ; } public String toString() { final String COMMA = ", " ; final StringBuffer buffy = new StringBuffer() ; buffy.append( "Item ( " ).append( super.toString() ).append( COMMA ) .append( "name = " ).append( this.name ).append( COMMA ) .append( "type = " ).append( this.type ).append( COMMA ) .append( "value = " ).append( this.value ).append( COMMA ) .append( " )" ) ; return buffy.toString() ; } } Your Digester's parse method will return you an instance of DocumentSummary instance with all item detail populated as expected.... Hope this works for you... On Sat, Mar 14, 2009 at 2:41 AM, Rashid Jilani <[email protected]>wrote: > Hi: gurus I have the following xml file that I like to map to Java objects > but don't know the right approach after just reading the Digester document > > > > <eSummaryResult> > > <DocSum> > > <Id>27731</Id> > > <Item Name="Title" Type="String">The American journal of > obstetrics and diseases of women and children</Item> > > <Item Name="MedAbbr" Type="String">Am J Obstet Dis Women > Child</Item> > > <Item Name="IsoAbbr" Type="String"></Item> > > <Item Name="NlmId" Type="String">14820330R</Item> > > > > <Item Name="pISSN" Type="String">0894-5543</Item> > > <Item Name="eISSN" Type="String"></Item> > > <Item Name="PublicationStartYear" Type="String">1868</Item> > > <Item Name="PublicationEndYear" Type="String">1919</Item> > > <Item Name="Publisher" Type="String">W.A. Townsend & > Adams,</Item> > > <Item Name="Language" Type="String">eng</Item> > > > > <Item Name="Country" Type="String">United States</Item> > > <Item Name="BroadHeading" Type="List"></Item> > > <Item Name="ContinuationNotes" Type="String"></Item> > > </DocSum> > > > > > > > > </eSummaryResult> > > > > My objects are > > > > public class DocumentSummary implements Serializable { > > > > private long id = 0; > > private List<Item> listItems = null; > > > > // Omitted Setter and getters for Brevity > > > > } > > > > public class Item implements Serializable{ > > private String name; > > private String type; > > private String value; > > > > // Omitted Setter and getters for Brevity > > > > > > > > } > > > > Here is my rules file, but I got stuck after parsing the "Id" tag and don't > know how to proceed further, any help would be appreciated. > > > > <digester-rules> > > > > <pattern value="eSummaryResult/DocSum"> > > > > <object-create-rule classname="digesterexample.DocumentSummary"/> > > > > > > <set-next-rule methodname="add" > paramtype="digesterexample.DocumentSummary"/> > > > > <set-properties-rule/> > > > > <bean-property-setter-rule pattern="Id" propertyname="id"/> > > > > <set-properties-rule/> > > > > > > > > > > </pattern> > > > > Thanks, > > RJ > > -- ************** Jay !!! __o _-\<,_ (_)/ (_) ************** - Think B4 U Print --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
