my dog learned polymorphism
The moose likes XML and Related Technologies and the fly likes JAXB mashalling? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JAXB mashalling?" Watch "JAXB mashalling?" New topic

JAXB mashalling?

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 397
I have a JAXB generated object in memory, and I want to mashal it to XML. But I want it directly as a String, not written out to a file. How do I do this? Right now, I am using a temperary file, like this...

JAXBContext jc = JAXBContext.newInstance(JAXB_PACKAGE);
Marshaller m = jc.createMarshaller();
OutputStream os = new FileOutputStream("temp.xml");
m.marshal(jaxbObj, os);

byte[] bXml = ioMgr.loadFileAsBuffer("temp.xml");
if(bXml != null){
xml = new String(bXml);
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 397
That worked great, thanks
I agree. Here's the link:
subject: JAXB mashalling?
It's not a secret anymore!