This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 388
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: 18541
    
    8

M Burke
Ranch Hand

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