commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Lee <>
Subject How to create a Java object if the xml element is in wrong place?
Date Thu, 24 Apr 2008 12:39:26 GMT

I am parsing an xml file to the digester xml rules to create objects.
The xml file we've got does not confront to the java model correctly. The
address and contact elements are under the person. The correct format would
have been the address element to be inside the contact.
Unfortunately I can not change the format of the xml but I have to find a
way using xmlrule to overcome this problem.
The format of the xml file is:
                        <address line1="29  Glen Street" line2="Tamara"
                        <contact telephoneno="0123456789"

The Java has been defined as:
Contact contact;
public void setContact(Contact contact) { = contact; }
public Contact getContact() { return contact; }
Address address
public void setAddress(Address address) { this.address = address; }
public Address getAddress() { return address; }
private String line1;
private String line2;
private String postcode;
setters/getters for line1,line2 and postcode;

my xml rule is:
<pattern value="root/person">
            <object-create-rule classname="" />
            <set-properties-rule />
            <set-next-rule methodname="setContact" />
<pattern value="root/person/contact">
            <object-create-rule classname="" />
            <set-properties-rule />
            <set-next-rule methodname="setAddress" />
<pattern value="root/person/address">
           <!-- How to write my rule here -->
            <object-create-rule classname="" />
            <set-properties-rule />
            <set-next-rule methodname="setAddress" />

If I add setAddress in then it works fine but setAddress is only
defined in
How can I write my address rule so that it work?

Any help I would appreciate.

Robert Lee
View this message in context:
Sent from the Commons - Dev mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message