You're absolutely right. I did suggest that option to transform my XML before
I use the rules but I've been told not to and second that the data is
dynamically gets populated.

I'll push again to use the XSLT transformation before I can use the rules
but at the same time wanted to know if it's possible to create Java object
if the xml element is in wrong place.


Thanks for your reply.


Robert
------------


Simone Gianni-2 wrote:
> 
> 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="[EMAIL PROTECTED]"></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: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/How-to-create-a-Java-object-if-the-xml-element-is-in-wrong-place--tp16850225p16935400.html
Sent from the Commons - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to