Solving this problem was easier than writing your own code.
To avoid this problem, you need to set the JAXB_FRAGMENT property to true in Marshaller. This property lets JAXB know that it is marching in the middle of the document and that it should not write a headline.
So, I stayed below the code before writing the BODY part:
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
And it works like a charm!
source share