Thanks Stephen,

I know I have looked at an XML serializer already but maybe I didn't look far enough. For the sake of the list archive, though, here is what I am doing now.

// find the element
// get its value into "val"
CDATASection cdata = document.createCDATASection(val);
if (cdata != null) {
        element.removeChild(child);
        element.appendChild(cdata);
}

Still feels like a hack to me but it is working and I need to move on. I'd like to have a generic solution, of course. This is a really specific solution so I'm going to continue to call it a hack.

Thanks again
Marc

On Mar 21, 2006, at 1:12 PM, Stephen Bash wrote:

Marc-

I don't know of a way to do achieve your goal in Castor, but that
doesn't mean one doesn't exist.

Looking through the Marshaller class though, I feel like you really
want to be down at the XML serializer level.  For example, when the
serializer receives a call to start element "foo" with attribute
"bar", just before it actually writes the output to a stream, you
intercept the value of bar and replace it with <![CDATA[value of
bar]]>.  Anything higher up the chain I'm afraid will end up getting
escaped by the serializer.  Sounds like a job for AspectJ if I ever
heard one :)  Sorry I can't be of more help.  Your post processing
might be the easiest way to go.

Stephen


On 3/21/06, Marc Respass <[EMAIL PROTECTED]> wrote:
Hi all,

I'm new to the list and just started using Castor. I'm impressed so
far but I've run into a problem. The party who has defined the XML
document demands that all values be wrapped in CDATA. Right now, I am
marshalling the object with Castor and then hacking the document by
calling getElementsByTagName(), pulling the value, creating a CDATA
section, removing the element's child, and appending the new CDATA
section. It would be cool if I could get the value wrapped in CDATA
automatically during the marshalling. I tried writing a
GeneralizedFieldHandler that would wrap the value like

value = "<![CDATA[" + value + "]]>";

but that is so wrong and the first "<" gets escaped. I've look around
and tried lots of different things but I have been entirely
unsuccessful. Can anyone point me in the right direction to do this?
Is it possible or is my hack not really a hack so I should change my
method name from hackDocument() to fixUpDocument()? :)

Thanks a lot
Marc

-------------------------------------------------
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