Another possible solution(java.io.ByteArrayOutputStream):
private String generateStringContent(Object objectToBeMarshalled) {
Mapping mapping = new Mapping();
String result = null;
try {
mapping.loadMapping(pathToMapping);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(bos);
Marshaller marshaller = new Marshaller(osw);
marshaller.setMapping(mapping);
marshaller.setValidation(false);
marshaller.marshal(objectToBeMarshalled);
result = bos.toString();
osw.close();
bos.close();
} catch (IOException e) {
logger.severe("IOException: " + e.getMessage());
e.printStackTrace();
} catch (MappingException e) {
logger.severe("MappingException: " + e.getMessage());
e.printStackTrace();
} finally {
return result;
}
}Jeremy Nicholson wrote:
Jana,
Have a look at marshalling to a StringWriter then you can do a getBuffer().toString()
Jeremy
-----Original Message----- From: janarthanankesavan [mailto:[EMAIL PROTECTED] Sent: 20 July 2004 07:59 To: [EMAIL PROTECTED] Subject: [castor-user] converting xml to string
Hi all, This is a general question. Can anyone provide me an example where you can convert the xml file into a java string object?
I am trying to convert the xml file which i got from castor to an string object.
Reg Jana
Life is not a bed of roses! ---------------------------- With warmest regards, T.K.Janarthanan.
<http://clients.rediff.com/signature/track_sig.asp>
------------------------------------------------------------------------
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
