commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Gianni <simo...@apache.org>
Subject Re: How to create a Java object if the xml element is in wrong place?
Date Fri, 25 Apr 2008 16:46:36 GMT
Probably I'm saying something stupid, but can't you just pass your input
XML in an XSLT and transform it to a form suitable to your needs? If you
just need to move blocks of XML from outside to inside other blocks it
should not be difficult.

Simone

Robert Lee wrote:
> 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:
> <root>
>             <person>
>                         <address line1="29  Glen Street" line2="Tamara"
> postcode="XYZ123"></address>
>                         <contact telephoneno="0123456789"
> emailaddress="glen@street.com"></contact>     
>             </person>
> </root>
>
> The Java has been defined as:
> Person.java
> -----------------
> Contact contact;
> public void setContact(Contact contact) { this.contact = contact; }
> public Contact getContact() { return contact; }
>
> Contact.java
> -----------------
> Address address
> public void setAddress(Address address) { this.address = address; }
> public Address getAddress() { return address; }
>
> Address.java
> -----------------
> 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="com.xyz.Person" />
>             <set-properties-rule />
>             <set-next-rule methodname="setContact" />
> </pattern>
> <pattern value="root/person/contact">
>             <object-create-rule classname="com.xyz.Contact" />
>             <set-properties-rule />
>             <set-next-rule methodname="setAddress" />
> </pattern>
> <pattern value="root/person/address">
>            <!-- How to write my rule here -->
>             <object-create-rule classname="com.xyz.Address" />
>             <set-properties-rule />
>             <set-next-rule methodname="setAddress" />
> </pattern>
>
> If I add setAddress in Person.java then it works fine but setAddress is only
> defined in Contact.java
> How can I write my address rule so that it work?
>
> Any help I would appreciate.
> Thanks.
>
> Robert Lee
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message