Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 35920 invoked from network); 4 Dec 2001 17:43:15 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 4 Dec 2001 17:43:15 -0000 Received: (qmail 7955 invoked by uid 97); 4 Dec 2001 17:43:17 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 7939 invoked by uid 97); 4 Dec 2001 17:43:17 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 7928 invoked from network); 4 Dec 2001 17:43:16 -0000 Date: Tue, 4 Dec 2001 09:24:40 -0800 (PST) From: "Craig R. McClanahan" Sender: craigmcc@localhost To: Jakarta Commons Developers List Subject: Re: Digester: Examples In-Reply-To: <00b001c17cd3$9d79e680$05ff000a@majorband.local> Message-ID: <20011204091811.L92884-100000@localhost> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: localhost 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N On Tue, 4 Dec 2001, Aravinda Addala wrote: > Date: Tue, 4 Dec 2001 14:54:44 -0000 > From: Aravinda Addala > Reply-To: Jakarta Commons Developers List > To: commons-dev@jakarta.apache.org > Subject: Digester: Examples > > Hi, > > I am new to Digester. I have looked at the examples and they are great to > understand. > > I want to create objects based on the properties. > My XML file contains several employees each has a ID as property. How can I > use digester to initialize a employee object based on ID? > > My XML looks like this: > > > > >
state="HS" zipCode="HmZip"/> >
state="OS" zipCode="OfZip"/> > > > >
state="HS" zipCode="HmZip"/> >
state="OS" zipCode="OfZip"/> > > > > > Please help. > > Regards, > Aravinda. > Assume you have the following JavaBeans: package com.mycompany.myapp; public class Employee { public Employee() { ... } public int getId(); public void setId(int id); public String getFirstName(); public void setFirstName(String firstName); public String getLastName(); public void setLastName(String lastName); public void addAddress(Address address); } package com.mycompany.myapp; public class Address { public Address() { ... } ... getters and setters for "type", "street", "state", "zipCode" ... } then the following rules should work fine: digester.addObjectCreate("employee", "com.mycompany.myapp.Employee"); digester.addSetProperties("employee"); digester.addObjectCreate("employee/address", "com.mycompany.myapp.Address"); digester.addSetProperties("employee/address"); digester.addSetNext("employee/address", "addAddress", "com.mycompany.myapp.Address"); The set properties rule will do conversions for all the native Java types, so an "id" property is no different than any other. However, you will need to put quotes around your id values -- it's not valid XML syntax to have unquoted attribute values. Craig -- To unsubscribe, e-mail: For additional commands, e-mail: