users@jaxb.java.net

Re: Marshalling in chunks?

From: <eguy66_at_optonline.net>
Date: Wed, 17 Aug 2005 12:00:03 -0400

(sorry, previous post sent as html)
Thanks for the info, but Marshaller.JAXB_FRAGMENT is not a property in jaxb 1.0

I think I'm close to a workaround for 1.0, but it may be specific to my problem and not something that can be generalized. The xml document I'm working with has a couple of text-only elements off the root element, followed by two repeating complex elements, basically a collection for documents and a second collection for addressees to receive the documents.

What I have done is create the jaxb objects for the root element and the text-only elements, and marshall them to a byte stream. I then create a "prolog" string and an "epilog" string, by finding the last instance of an opening tag, "<". I create a file output stream and write out the prolog. Next, I set the property, "com.sun.xml.bind.xmlDeclaration", to false. I then enter a loop to build the jaxb for each document, and marshall each document to the file output stream. I do the same for the collection of addressees. Finally, I write out the epilog string and close the file.

This results in the document I am trying to create, with one exception. The root element correctly contains all the namespace definitions I need, but each document and addressee element also contains the same namespace definitions, significantly and unnecessarily increasing the size of the output file.

Is there any way to suppress the redundant namespace definitions? Below is a current output sample.

TIA,

Ed

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

<Marsh:GetCertificateInfo xmlns:Marsh="http://www.marsh.com/" xmlns="http://www.ACORD.org/standards/PC_Surety/ACORD1.6.0/xml/">

<Marsh:LocalPrintInd>1</Marsh:LocalPrintInd>

<Marsh:DraftInd>1</Marsh:DraftInd>

<Marsh:CertificateInfo xmlns:Marsh="http://www.marsh.com/" xmlns="http://www.ACORD.org/standards/PC_Surety/ACORD1.6.0/xml/"/>

<Marsh:CertificateInfo xmlns:Marsh="http://www.marsh.com/" xmlns="http://www.ACORD.org/standards/PC_Surety/ACORD1.6.0/xml/"/>

<Marsh:AddresseeInfo xmlns:Marsh="http://www.marsh.com/" xmlns="http://www.ACORD.org/standards/PC_Surety/ACORD1.6.0/xml/">

<Marsh:AdresseeId>000</Marsh:AdresseeId>

</Marsh:AddresseeInfo>

<Marsh:AddresseeInfo xmlns:Marsh="http://www.marsh.com/" xmlns="http://www.ACORD.org/standards/PC_Surety/ACORD1.6.0/xml/">

<Marsh:AdresseeId>001</Marsh:AdresseeId>

</Marsh:AddresseeInfo>

</Marsh:GetCertificateInfo>

 

----- Original Message -----
 
From Ryan Shoemaker - JavaSoft East <Ryan.Shoemaker_at_Sun.COM>
Date Tue, 16 Aug 2005 16:33:18 -0400
To users_at_jaxb.dev.java.net
Subject Re: Marshalling in chunks?



--------------------------------------------------------------------------------

Ryan Shoemaker - JavaSoft East wrote:
> eguy66_at_optonline.net wrote:
>
>>
>> I thought setting the xmlDeclaration property to false might solve
>> things, but it had no effect. Any suggestions?
>>
>
> This sounds like a bug. For one, we now have a portable property
> Marshaller.JAXB_FRAGMENT rather than the RI specific property. I'll
> confirm some details and fix the code...
>

I ran some test code and it looks like Marshaller.JAXB_FRAGMENT takes
precedence over the com.sun.xml.bind.xmlDeclaration RI specific property.
If you use:

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

it will suppress things as expected. Take a look at the javadoc for the
property though - it does slightly different things depending on what you
are sending the marshalled data to. In your case (ContentHandler), we
suppress the calls to startDocument() and endDocument().

Thanks,

--Ryan