Chembu-
First let me say I'd prefer that such e-mails be sent to the Castor
list rather than directly to my e-mail address. This keeps the
discussion available for others in the future and allows the larger
community to comment on your question. I'm replying to the users list
and I'd rather the conversation follow there.
To answer your question, I don't think it's possible right now without
writing an XMLFieldDescriptor for your classes. In the Marshaller on
line 1378 the Marshaller fetches the value of the xml:space attribute
from the XMLFieldDescriptor and if non-null, applies that value to the
current element. As far as I can tell from the Xerces XMLSerializer
code, Xerces will respect that attribute and preserve whitespace if
the attribute exists.
The problem is, AFAIK, there's no way to set the xml:space attribute
in the FieldDescriptor in the current implementation (except by
writing your own FieldDescriptor). Can someone else comment on this?
I think in a global sense a Marshaller.setPreserveWhitespace would be
a good method to have...
Stephen
---------- Forwarded message ----------
Date: May 2, 2007 1:14 PM
Subject: [Fwd: Re: How to avoid whitespace trimming]
To: [EMAIL PROTECTED]
-------- Original Message --------
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Re: How to avoid whitespace trimming
Date: Tue, 01 May 2007 13:22:35 -0700
Hi Stephen,
Just wondering about how I can preserve whitespaces during Marshalling.
I use the following code for Marshalling.
StringWriter entityWriter = new StringWriter();
Marshaller marshaller = new Marshaller(entityWriter);
marshaller.marshall(Object);
During Marshalling Castor trimms down the whitespaces. What needs to be
added in the following code to preserve whitespaces? I don't use mapping
files.
Thanks a lot in Advance..
Chembu
Stephen Bash wrote:
Ralf and Alan-
While digging through the UnmarshalHandler for something completely
unrelated, I think I came across your solution. Castor looks for the
attribute space in the namespace http://www.w3.org/XML/1998/namespace,
which if set to "preserve" (it is case sensitive), Castor will not strip
trailing whitespace.
So my sample output looked like this:
<?xml version="1.0" encoding="UTF-8"?>
<string-holder xmlns:xml="http://www.w3.org/XML/1998/namespace">
<str xml:space="preserve">This is a test . </str>
</string-holder>
And in Java all the spaces were preserved.
HTH,
Stephen
Ralf Joachim wrote:
Hi Alan,
what version of castor are you using?
I think I can remember having seen some mails or an issue in jira where
someone provided a solution for a situation where he also lost some
whitespaces. Therefore I suggest you to search jira or mailing lists. Or
could anyone else have a solution or can remember better then I do.
Regards
Ralf
Castor JDO, committer
Alan Andrade schrieb:
Hi
Need help is switching off whitespace trimming ..
Eg
<class>Alan' Class</class>
Is printed as Alan'Class
Is there a way to make castor ignore whitespaces rather than trim them?
Thanks
Alan
-------------------------------------------------
If you wish to unsubscribe from this list, please
send an empty message to the following address:
[EMAIL PROTECTED]
-------------------------------------------------
Quoted from:
http://www.nabble.com/How-to-avoid-whitespace-trimming-tf907852.html#a2448948
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email