madhununna said:
"Anton Spaans" <aspaans at(noSPAM) smarttime dot(noSPAM) com> wrote in
message news: said:
madhununna said:
"Anton Spaans" <aspaans at(noSPAM) smarttime dot(noSPAM) com> wrote in
message news: said:
"Anton Spaans" <aspaans at(noSPAM) smarttime dot(noSPAM) com> wrote in
message
I'm trying to parse string data using castor and it looks like
the
new
lines are getting lost.
I'm using castor 0.9.4.3
For example:
Input
<INPUT> First line
second line
third line </INPUT>
after marshaling and unmarshaling using castor this becomes
<INPUT> First line second line third line </INPUT>
Is there something I can do to preserve the newlines in the data
or
is
this a bug in castor.
Thanks in advnce for the help
This looks fine. This is normal behavior for XML. Spaces are consolidated.
A
contiguous list of whitespace characters (space, carriage return,
tab,
etc)
are consolidated into one.
To avoid this, embed the data in your INPUT element into a CDATA section
and
try again:
<INPUT>><![CDATA[First Line
second line
third line]]></INPUT>
-- Anton Spaans.
Oops.. i made a typo. Instead of <INPUT>> it should be <INPUT>
I tried it and did not work
Given below is the xml input before and after marshaling with castor
Before marshaling
<?xml version="1.0" encoding="UTF-8"?>
<ScriptConfiguration>
<ScriptCommands><![CDATA[
function matchwo(a,b)
{
if (a < b && a < 0) then
{
return 1
}
else
{
return 0
}
}
]]>
</ScriptCommands>
</ScriptConfiguration>
After marshaling with castor
<?xml version="1.0" encoding="UTF-8"?>
<ScriptConfiguration>
<ScriptCommands>function matchwo(a,b){if (a < b && a
< 0) then { return 1 }else { return
}} said:
mmmm.... I guess castor creates a _scriptCommands member in the
ScriptConfiguration class, which will be set (when unmarshalling into
objects) to the cdata-string (including the multiple
spaces/carriage-returns) from the input. But when marshalling the object
back to XML, the _scriptCommands string is output as a regular text-node,
not a cdata-section.....
What are you using for marshalling? marshal(ContentHandler) or
marshal(Writer).?
Try to use the marshal(Writer).
-- Anton.
I'm using Marshaller(StringWriter) and also the only option I'm
setting on the marshaller is validations which I'm setting to false.
I'm using the marshal(Object) method.
-Madhu
??? mmmmmmmmm... have you tried the one that takes a ContentHandler or
DocumentHandler?
When you unmarshalled the XML into an object, what are the contents of that
'String _scriptCommands' member?
Does it contain carriage-returns/etc. ? If so, the unmarshalling goes fine
and the marshalling back into an XML goes wrong. And if so, why would you
generate back to XML again (xml --> objects --> xml)?
At my company we are using 0.9.3.21. We never upgraded because of namespace
issues. Exolab decided to properly implement the namespace handling (very
nice), but not an option to properly turn namespace handling off. It would
have required us to re-write maaannnyyy XSL stylesheets.
In our product
we marshal Java Strings (as part of Castor generated objects) with carriage
returns into XML that is used by the XSLs to generate <TEXTAREA>
html-elements. This works fine. Carriage returns show up correctly in the
browser, less-than signs show as '<', etc.
These are our runtime options (castor.properties):
org.exolab.castor.parser=org.apache.xerces.parsers.SAXParser
org.exolab.castor.serializer=com.smarttime.mvc.CastorSerializer
(this is our own serializer.... but the only thing it does is getting rid of
namespace declarations....)
org.exolab.castor.xml.introspector.primitive.nodetype=attribute
#org.exolab.castor.indent=true
(this one is commented out)
org.exolab.castor.parser.validation=false
org.exolab.castor.parser.namespaces=false
org.exolab.castor.marshalling.validation=false
Otherwise, try to find an answer at
http://www.exolab.org
Good luck.