« Return to Thread: @XmlCDATA omit CDATA when element is empty?

Re: @XmlCDATA omit CDATA when element is empty?

by Blaise Doughan :: Rate this Message:

| View in Thread

Hi James,

I apologize for the delay in responding.  The approach you are trying is a good one, I'm still thinking about how to support your null use case.  When you have a value is it wrapped with CDATA even if a CDATA block isn't required?

-Blaise

On 22/03/2012 2:33 PM, James Carr wrote:

> I kind of found a solution for this, but unfolding scenarios made my
> solution invalid. :(
>
> For those who might be reading, I was able to use the following:
> @XmlCDATA
> @XmlNullPolicy(nullRepresentationForXml =
> XmlMarshalNullRepresentation.EMPTY_NODE, emptyNodeRepresentsNull =
> true)
>
> By setting fields to null it gives me the empty tag that I wanted
> (with no CDATA wrapper).
>
> Unfortunately, it looks like the legacy XML is generated with these rules:
>
> 1 - value = value wrapped in CDATA Tag
> 2 - empty string = empty node
> 3 - null = no node.
>
> So I'm back in the same boat. If anyone has any ideas on how I can get
> around this problem, I'd be grateful.
>
> Thanks,
> James
>
>
>
> On Wed, Mar 21, 2012 at 11:19 AM, James Carr<james.r.carr@...>  wrote:
>> Hi All,
>>
>> I'm currently working on a project where I need to produce the same
>> XML as a legacy system and one funny behavior the old system has is it
>> always wraps each elment value in a CDATA tag. At first we thought
>> @XmlCDATA would be exactly what we need and it is, however the old
>> system omits the CDATA tag if the element value is blank.
>>
>> Any ideas how I could accomplish this? I keep thinking that an
>> @XmlWriteTransformer might be what we need but I'm  unsure of how to
>> use it.
>>
>>
>> Thanks,
>> James
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@...
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
_______________________________________________
eclipselink-users mailing list
eclipselink-users@...
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

 « Return to Thread: @XmlCDATA omit CDATA when element is empty?