Thank you Jamie, yes I already downloaded the JAR but I'm getting a new
Exception on the setEncoding() line: java.lang.IllegalStateException: encoding
cannot be set if you've passed in your own DocumentHandler.

  But I think that's another problem, according to a mail in the archive I
should be able to perform the marshalling with a particular encoding without
the Marshaller#setEncoding() method, in that mail Keith wrote: 

"Hi Torsten,

We don't currently have a convenience method for this, but
you can get a handle on the Serializer and set the encoding yourself.

Take a look at 

org.exolab.castor.util.Configuration#getSerializer

which returns an org.apache.xml.serialize.Serializer

-and-

org.exolab.castor.util.Configuration#getOutputFormat

which returns an org.apache.xml.serialize.OutputFormat


So you want something like:

OutputFormat format = Configuration.getOutputFormat();

format.setEncoding(...);

Serializer serializer = Configuration.getSerializer();

serializer.setOutputFormat(format);

serializer.setOutputCharStream(writer);

Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());"


This is my actual code, and correct me if I'm wrong but I think it's the same
stuff:

OutputStreamWriter osw = new OutputStreamWriter(System.out);
w = new BufferedWriter(osw);
OutputFormat format = org.exolab.castor.util.Configuration.getOutputFormat();
format.setEncoding("ISO-8859-1");
Serializer serializer = org.exolab.castor.util.Configuration.getSerializer();
serializer.setOutputFormat(format);
serializer.setOutputCharStream(w);

Marshaller marshaller = new Marshaller(serializer.asDocumentHandler());
marshaller.marshal(myObj, w);


  Thanks.

--------------------------------------------------------------------------------

From: Jamie De Wet 
Subject: Re: [castor-dev] Marshalling encoding 
Date: Tue, 23 Jul 2002 21:48:08 -0700 

--------------------------------------------------------------------------------

Title: RE: [castor-dev] Marshalling encoding
2. Had this problem with JBuilder yesterday - the Castor.jar that JBuilder uses
is saved in eg. jbuilder/lib directory. Download the latest version of Castor
and save it in the JBuilder/lib directory. Make sure you rename the downloaded
jar to castor.jar. JBuilder will then pick up this new version. The latest
version of Castor has the marshaller.setEncoding(....).

Hope this solves one of your problems 
Jamie 


------------------------------------
Mail.Ru - ������, ��������, �������!
------------------------------------

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to