users@jaxb.java.net

How to marshal two or more content trees into a single XML document

From: Johnny Tolliver <jxt_at_ornl.gov>
Date: Fri, 14 Oct 2005 18:04:56 -0400 (EDT)

I have code that receives XML requests that get unmarshalled with JAXB. For
example,

<?xml version="1.0" encoding="UTF-8"?>
<SomeTag>
  <SomeRequest id="xxx">
    <RequestParameters aaa="bbb"/>
  </SomeRequest>
</SomeTag

and the reply, after marshalling is

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SomeTag>
  <SomeReply id="xxx">
    more stuff about xxx query
  </SomeReply>
</SomeTag>

Simple. Now, I want to support receiving multiple requests. I.e.,

<?xml version="1.0" encoding="UTF-8"?>
<SomeTag>
  <SomeRequest id="xxx">
    <RequestParameters aaa="bbb"/>
  </SomeRequest>
  <SomeRequest id="yyy">
    <RequestParameters aaa="ccc"/>
  </SomeRequest>
</SomeTag

If I process these requests in a loop to generate the reply information and
marshal the content tree, then I end up marshalling twice so that the reply
looks like

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SomeTag>
  <SomeReply id="xxx">
    more stuff about xxx query
  </SomeReply>
</SomeTag>

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SomeTag>
  <SomeReply id="yyy">
    more stuff about yyy query
  </SomeReply>
</SomeTag>

Instead of that I want it all together, like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<SomeTag>
  <SomeReply id="xxx">
    more stuff about xxx query
  </SomeReply>
  <SomeReply id="yyy">
    more stuff about yyy query
  </SomeReply>
</SomeTag>

The structure of the code makes it not so easy to build a single content tree
that looks like the latter, desired reply. Is there any way to marshal the two
replies into a single reply as shown? Is this what is known as partial
marshalling or fragment marshalling?

Thanks,
Johnny S. Tolliver
Oak Ridge National Laboratory
tolliverjs_at_ornl.gov, 865-574-1305