users@jaxb.java.net

RE: marshal without envelope tag

From: Damon Goodyear <damongoodyear_at_hotmail.com>
Date: Tue, 23 Dec 2008 15:28:32 +0000

Others will correct me if I'm wrong but... I am feeling (semi)* public spirited today. I believe if you set JAXB_FRAGMENT to Boolean.TRUE then you can marshall only the object.
 
I have a similar problem. I want to marshall a number myObjects (indeterminate when I start processing) and I want to--
 
i. marshall them on a different thread - so as to isolate my processing from marshalling, and
ii. wrap the whole lot in an envelope at the end of processing. (Alternatively right the envelope out programmatically without haing to write something like--
 
out.println("<xml...");
m.marshall(MyObj, out)
out.println("</xml...");
 
... cos I might have a few different myObj's to marshall and doing this each time looks very cumbersome.
 
As you say there seems to be no way to do this elegantly. XMLBeans seems to do this but I really would rather not have to go through the torture of learning (yet another) API (admittedly it doesn't look that steep now that I know a little about JAXB). If anyone has a solution that doesn't involve the above then I'd be very interested to hear it.
Damon Goodyear > Date: Tue, 23 Dec 2008 15:57:27 +0100> From: guf_at_kajak.org.pl> To: users_at_jaxb.dev.java.net> Subject: marshal without envelope tag> > Suppose I have an object myObject of a class generated by JAXB. I would> like to marshall myObject to XML without envelope tag. In JAXB v1 I used> to write:> > marshaller.marshal( myObject, outputStream );> > But when I try the same with JAXB v2 I get an MarshalException:> [com.sun.istack.SAXException2: unable to marshal type "MyType" as an> element because it is missing an @XmlRootElement annotation]> > I know that I can avoid this exception by i.e. wrapping myObject with> JAXBElement with some QName object but it marshal to XML with envelope tag> correnponding to the QName object. But I don't want to have the envelope> tag.> > Is there any elegant solution to my problem?> > Of course I can marshal to string with an envelope tag and trim off the> envelope tag. But it is not an elegant solution.> > Regards,> -tt.> > > ---------------------------------------------------------------------> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net> For additional commands, e-mail: users-help_at_jaxb.dev.java.net>