Stephen,
Thank you. I'll give it a try. It looks surprisingly similar to the
GeneralizedFieldHandler that I wrote. I have this method
public Object convertUponGet(Object value) {
value = "<![CDATA[" + value + "]]>";
return value;
}
but the first "<" gets escaped as <
I'll try this though and let you know.
Thanks again
Marc
On Mar 21, 2006, at 2:36 PM, Stephen Bash wrote:
Marc-
Just going through the archives looking for something else I stumbled
across this message:
http://marc.theaimsgroup.com/?l=castor-user&m=112792379518919&w=2
I'm not sure if it will work in your specific case, but it might be
helpful.
Stephen
On 3/21/06, Marc Respass <[EMAIL PROTECTED]> wrote:
On Mar 21, 2006, at 2:14 PM, Benoit Maisonny wrote:
I'm curious to know why you need to put the values in CDATA
sections.
So am I. I'm making an XML file that is sent to someone and that's
what they require. When I asked why, they ignored me.
The serializer escapes anyway any character that need to be escaped
according to XML specs (if not, than the serializer is buggy). So,
I don't see a need to use CDATA at all.
I couldn't agree more. Besides that, the data is all simple short
values.
As far as I know, CDATA sections are only useful to humans, as we
don't like to have to escape characters manually. But maybe I miss
some weird use of CDATA.
CDATA is sometimes useful and I've used it before but this is not a
good use of CDATA. Frankly, I suspect the guys who are receiving this
file are using String.indexOf() as their parser ;).
However, one may desire enclosing a value in CDATA and it seems like
something useful to have. I've found a number of questions about how
to go about it and none of the answers are very easy. I was hoping
there was something that I missed in Castor but it looks like writing
my own serializer is the way.
Marc
Benoit
Marc Respass wrote:
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]
-------------------------------------------------
--
Benoit Maisonny [EMAIL PROTECTED]
Director & Consultant http://synclude.com
Synclude
-------------------------------------------------
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]
-------------------------------------------------
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------