users@jaxb.java.net

Re: XML declaration control

From: Kenny MacLeod <kennym_at_kizoom.com>
Date: Thu, 14 Aug 2008 22:01:47 +0100

Given that the reference docs you linked to say to do this:

marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

then why are you doing this?

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


kenny


Chris Richmond wrote:
> 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
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>