One solution is to write a custom FieldHandler that can check to see if your field is "empty". If so simply return null from the getValue() method in the FieldHandler.

For more on writing FieldHandler's please see:

http://castor.codehaus.org/xml-fieldhandlers.html

Hope that helps,

--Keith

Andrew Fawcett wrote:
Hi,



I think you're correct in your assumption that it's because you have

instance of the object itself. It is this that represents the parent tag

in Castor terms. So you have to null this reference to have it not

output the parent tag. In order to implement this I guess Castor would

have to know if an object is "empty" in XML terms. Something I know it

doesn't do already, sorry.



Cheers,



Andy.



-----Original Message-----

From: Henk Schets [mailto:[EMAIL PROTECTED]
Sent: 23 August 2005 08:12

To: [email protected]

Subject: [castor-user] how to avoid empty elements ?



Hi,



I'm using Caster to marshal a List of javabeans to xml. Sometimes one of these beans is not null, but all of it's fields are empty. In that case, Castor just outputs the xml with all elements empty. Is there a
way to tell Caster not to write the xml when this is the case ?



Thanks



Henk



PS I tried to look this up in the forums or the wiki, but both are
unreacheable for the moment.



-------------------------------------------------

If you wish to unsubscribe from this list, please
send an empty message to the following address:



[EMAIL PROTECTED]

-------------------------------------------------







CODA has a new world-class consolidation package.

Find out more about www.coda.com/ocra <http://www.coda.com/ocra>




The information in this message is confidential and may be legally privileged. 
It may not be disclosed to, or used by, anyone other than the addressee. If you 
receive this message in error, please advise us immediately.  Internet emails 
are not necessarily secure. CODA does not accept responsibility for changes to 
any email which occur after the email has been sent. Attachments to this email 
may contain software viruses, which could damage your systems. CODA has checked 
the attachments for viruses before sending, but you should virus-check them 
before opening.  



-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------




-------------------------------------------------
If you wish to unsubscribe from this list, please send an empty message to the following address:

[EMAIL PROTECTED]
-------------------------------------------------

Reply via email to