aspose file tools*
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
Author

JAXB mashalling?

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 382
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
Bartender

Joined: Oct 14, 2005
Posts: 18141
    
    8

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 382
That worked great, thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAXB mashalling?
 
Similar Threads
Read and create a XML file
XML to Java object using JAXB
Is there a java API to generate xml with an inline schema definition
trouble calling a java imported class in a jsp page
XPATH Processor in java code