users@jaxb.java.net

XML declaration control

From: Chris Richmond <crichmond_at_referentia.com>
Date: Thu, 14 Aug 2008 09:54:30 -1000

Hello,

I am using JAX-WS RI 2.1.4 and the JAXB that comes with that and I am
attempting to compose an xml document from several schema generated classes
using Marshalling and I don't want the xml declaration coming out before
every single object I marshal to the output, so I attempted to turn off xml
declaration using the following methods:


m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

This has no effect. Every item I marshal out using:

m.marshal(new JAXBElement(new QName("http://my.uri.com","MyObjectClass"),
MyObjectClass.class, myObjectClassInstance), System.out);

still outputs the:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>


So I end up with:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<my marshaled object>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<my marshaled object>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<my marshaled object>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<my marshaled object>


When I want to be able to turn that option off preferably after I mashal the
first object in the output document and get:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<my marshaled object>
<my marshaled object>
<my marshaled object>
<my marshaled object>


I could live without having the xml declaration at all if necessary, but
since it appears to be only a flag then I don't see why it couldn't just be
set after the first marshaled object is written.

Incidentally, I got this from the following reference:

http://java.sun.com/webservices/docs/2.0/jaxb/vendorProperties.html#xmldecl


What am I doing wrong here?


Thanks,

Chris