This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "JAXB mashalling?" Watch "JAXB mashalling?" New topic
Author

JAXB mashalling?

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 396
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);
os.close();

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

Joined: Oct 14, 2005
Posts: 19747
    
  10

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 396
That worked great, thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAXB mashalling?
 
It's not a secret anymore!